RE: Uploading Help
Unless you run your own server, this may not work because the web host may not have decided to update their version of Perl or CGI.pm yet. For instance, my hosting service is still using Perl 5.005_03 with CGI.pm version 2.46. So I tried the preferred upload method with no success. The previous method for reading uploaded files might have been slightly convoluted, but it still works... Scot Robnett inSite Internet Solutions [EMAIL PROTECTED] http://www.insiteful.tv There are only two things in life, but I forget what they are. - John Hiatt --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Uploading Help
for some reason when, I do this it doesnt print any thing, it just makes the file. sub uploadfile { for ($i=1; $i=5; $i++) { if ($q-param(file$i)) { $filename = $q-param(file$i); $file = $q-param(file$i); $filename =~ s/.*[\/\\]//; open (FILE,$user{'site_id'}/$filename) || error(Could not create $filename: $!); { local $/=; my $uploaded = $file; print FILE $uploaded; } close FILE or die $!; } } } = __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Uploading Help
True. The only print statement I see here is the one which prints the contents of $uploaded to FILE. Maybe after you do this, you want to either print out an HTML response or redirect to another page? If so, you need to write more code to do that. - John --- LinkS On WeB [EMAIL PROTECTED] wrote: for some reason when, I do this it doesnt print any thing, it just makes the file. sub uploadfile { for ($i=1; $i=5; $i++) { if ($q-param(file$i)) { $filename = $q-param(file$i); $file = $q-param(file$i); $filename =~ s/.*[\/\\]//; open (FILE,$user{'site_id'}/$filename) || error(Could not create $filename: $!); { local $/=; my $uploaded = $file; print FILE $uploaded; } close FILE or die $!; } } } = Now it's over, I'm dead, and I haven't done anything that I want; or, I'm still alive, and there's nothing I want to do. - They Might Be Giants, http://www.tmbg.com __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Uploading Help
Oh! Upon re-reading I realize you probably meant that nothing is printed to the file, you are just getting an empty file created. Sorry for misunderstanding. Unfortunately, I don't have any experience in uploading files, so I'm sure that others on this list can be of more help than I can. (In fact, I'm about to make my own first attempt at this, so I can tell you more in a few days!) - John --- John Brooking [EMAIL PROTECTED] wrote: True. The only print statement I see here is the one which prints the contents of $uploaded to FILE. Maybe after you do this, you want to either print out an HTML response or redirect to another page? If so, you need to write more code to do that. - John --- LinkS On WeB [EMAIL PROTECTED] wrote: for some reason when, I do this it doesnt print any thing, it just makes the file. ... etc. = Now it's over, I'm dead, and I haven't done anything that I want; or, I'm still alive, and there's nothing I want to do. - They Might Be Giants, http://www.tmbg.com __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Uploading Help
Links On Web wrote at Fri, 14 Jun 2002 07:20:17 +0200: for some reason when, I do this it doesnt print any thing, it just makes the file. sub uploadfile { for ($i=1; $i=5; $i++) { if ($q-param(file$i)) { $filename = $q-param(file$i); $file = $q-param(file$i); $filename =~ s/.*[\/\\]//; open (FILE,$user{'site_id'}/$filename) || error(Could not create $filename: $!); { local $/=; my $uploaded = $file; print FILE $uploaded; } close FILE or die $!; } } I'm also not an expert of uploading files. But you do two things to read the file: $file = $q-param(file$i); Now $file contains a string. Then you use something like my $uploaded = $file; So now you use $file as a Filehandle, but in fact it's still a simple stupid string. Greetings, Janek BTW: Links on Web and email adress [EMAIL PROTECTED] doesn't seem to be very serious. You should become more serious if you really want something else than junk mail. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Uploading Help
--- Janek Schleicher [EMAIL PROTECTED] wrote: I'm also not an expert of uploading files. But you do two things to read the file: $file = $q-param(file$i); Now $file contains a string. Then you use something like my $uploaded = $file; So now you use $file as a Filehandle, but in fact it's still a simple stupid string. It would seem that way, but this is not the case. From the CGI.pm documentation: When the form is processed, you can retrieve the entered filename by calling param(): $filename = $query-param('uploaded_file'); [snip] The filename returned is also a file handle. You can read the contents of the file using standard Perl file reading calls: # Read a text file and print it out while ($filename) { print; } This has long been a convenience provided for by the CGI module. for some reason when, I do this it doesnt print any thing, it just makes the file. Offhand, I don't see anything wrong with the code. I have two questions: can you show us the HTML and are you using enctype=multipart/form-data in your form tag? Here's a quick rewrite of how I would probably lay this out. There's still some more stuff that can be done here, but this should get you going. Feel free to ask why I did something the way that I did. use File::Basename; # later my $files_uploaded = uploadfiles( $q, \%user ); sub uploadfile { my ( $q, $user ) = @_; # localize $_ so we don't step on it outside of the block local $_; my $file_count = 0; for ( 1 .. 5 ) { if ( my $file = $q-param( file$_ ) { my $filename = basename( $file ); open FILE, $user-{'site_id'}/$filename or error(...); binmode $file; print FILE $file; $file_count++; } close FILE or die $!; } return $file_count; } Cheers, Curtis Ovid Poe = Ovid on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Uploading Help
Crud! This is what I get for typing a program directly into a browser window :) for ( 1 .. 5 ) { if ( my $file = $q-param( file$_ ) { my $filename = basename( $file ); open FILE, $user-{'site_id'}/$filename or error(...); binmode $file; print FILE $file; $file_count++; } close FILE or die $!; Try switching the close and final curly in the above snippet: close FILE or die $!; } If you don't, you'll die the first time you try to close a file that you failed to open since I messed up the scope. Sorry 'bout that! Cheers, Curtis Ovid Poe = Ovid on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Uploading Help
Ovid wrote at Fri, 14 Jun 2002 16:43:51 +0200: It would seem that way, but this is not the case. From the CGI.pm documentation: When the form is processed, you can retrieve the entered filename by calling param(): $filename = $query-param('uploaded_file'); [snip] The filename returned is also a file handle. You can read the contents of the file using standard Perl file reading calls: # Read a text file and print it out while ($filename) { print; } } This has long been a convenience provided for by the CGI module. Oh, cool! Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]