Re: I have problems with download scripts, it's trying to print instead of saving the file



E Arredondo <atk@xxxxxxxxxxxxx> wrote:

> #!/usr/bin/perl -w
>
> use CGI;


You are missing a line that should be included in all of your Perl programs:

use strict;


> $filename = $query->param("photo");
> $filename =~ s/.*[\/\\](.*)/$1/;


perldoc File::Basename


> $upload_filehandle = $query->upload("photo");


That variable contains a *string*, not a filehandle...


> open UPLOADFILE, ">$upload_dir/$filename";


You should always, yes *always*, check the return value from open():

open UPLOADFILE, ">$upload_dir/$filename" or
die "could not open '$upload_dir/$filename' $!";


> while ( <$upload_filehandle> )


You need to put an _actual_ filehandle inside the input operator.


><HEAD>
><TITLE>Thanks!</TITLE>
><HEAD>
><TITLE>Thanks!</TITLE>
></HEAD>


That is a rather bizarre document structure...


> And here's the log file :
> binmode() on closed filehandle UPLOADFILE at


Your open() failed, but you didn't know it because you did
not check its return value.


--
Tad McClellan SGML consulting
tadmc@xxxxxxxxxxxxxx Perl programming
Fort Worth, Texas
.



Relevant Pages

  • Re: Opening .dat file in perl
    ... use warnings; ... use strict; ... you are allowed to read from the $fh filehandle. ... perl fdmacdr.pl ...
    (perl.beginners)
  • Re: use strict and filehandles
    ... > subroutine identifier, in curly brackets or to the left of the ... Using a bare word in the filehandle ... In this case a bare word does everything I need ... I guess use strict is trying to make sure I ...
    (perl.beginners)
  • Re: create columns from lines in perl
    ... > the output to a filehandle instead of to standard out. ... You need to spend a bit of time learning how to use the perl ... perldoc perl - this will tell you all the other resources perldoc ... printf FILEHANDLE FORMAT, LIST ...
    (comp.lang.perl.misc)
  • Re: File handling with subroutines and references
    ... I am using variable names for the FILEHANDLE to prevent any conflicts during processing ... no strict 'refs'; ...
    (comp.lang.perl.misc)
  • Re: print with +split
    ... ok in perldoc print it states: ... FOO is my filehandle and it is considered a variable meaning $_ right? ... > I looked in my programming perl and could not find it. ...
    (perl.beginners)