in reply to file uploading

I suggest that you read the file upload section of the CGI.pm documentation once more to ensure that you understand the process. In order to write out the uploaded file, you should open a file for writing, not a directory.

Replies are listed 'Best First'.
Re: Re: file uploading
by Anonymous Monk on Apr 15, 2003 at 17:14 UTC
    Ok, I guess that would be a problem then. Then I am more confused. How can you open a FILE for writing/uploading? I don't understand how you can have a form where a user uploads images and have those saved to a .txt or .else files. That's why I figured I'd set it to a directory. How do you save the uploaded file inside of another file?
      It is well documented in the CGI documentation as well as here in the Monastery. Remember that Super Search is your friend.
        Actually I did use both sources and didn't find any helpful information. I typically frown own reading module information on CPAN and elsewhere because they're not really helpful, you need to look at premade scripts to see why things work. Below is my new file, I changed it to save to a file 'text.txt' and it doesn't work. It makes the file text.txt but it has zero bytes, looks like all it does is create the file. It never shows what kind of file you need to open for this to work so I tossed in the text file, is this wrong?
        use warnings; use CGI qw/:standard/; use CGI::Carp 'fatalsToBrowser'; use POSIX; print header, start_html('upload form'); my $filename = "text.txt"; binmode($filename); print start_form(), table( Tr( td("File: "), td(filefield(-name=>'upload', -size=>50, -maxlength=>80), ), ), Tr( td(), td(submit('button','submit'), ) ) ), end_form(), hr; if (param()) { my $upload = param('upload'); while (<$filename>) { print; } open (OUTFILE,">>/home/myname/public_html/upload/text.txt") || die + $!; binmode(OUTFILE); while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; print "the thing is open"; } print "The file should be uploaded if everything went right, which it +probably didn't.\n"; }