File upload probelem
Anonymous Monk
created: 2006-04-05 07:52:42
Dear Monks, I have a cgi script which uses forms to pass information into a sql table. The script reloads its self dependent on the number of entries defined by the user. This works perfectly fine. However, I am having problems uploading the file defined by the user - using html form types. The name of the file is created but nothing written to it. The following code takes the information from the form which is used to update sql. I have omitted the the post methods to process info .
$previouspage =$ENV{'HTTP_REFERER'};
### i know this is not the best solution

if ($previouspage =~ m/int/) {
##define scalars.



$query = new CGI;
$filename = $query->param("profile_data");  #read infilename of data

   open(OUTPUT, ">$filename");
   binmode $filename;
   binmode OUTPUT;
   ($bytesread,$buffer,$total);

   while ($bytesread = read($filename,$buffer,1024) ) {
       $total += $bytesread;
               if ($bytesread > 10000000) { 
                          close(OUTPUT);
       unlink "$filename";
                                           }
                 print OUTPUT $buffer;
                                                     }
                                                                                                                 close(OUTPUT);
    }


Thanks
Re: File upload probelem
created: 2006-04-05 08:28:05
i have tested the upload code on a simple web form and it works fine. So its not a read/write permission problem.
Re: File upload probelem
created: 2006-04-05 08:38:32

Well, you've omitted the form (and left us guessing at exactly what is going on, since you don't mention _how_ it isn't working. But for a wild guess I'd say you didn't set the 'enctype' of the form correctly, if you are using CGI.pm to build your form make sure you are using start_multipart_form() and not start_form(), if you are writing your own form tags, make sure your form tag includes enctype="multipart/form-data" and consider reading the file upload portions of the CGI.pm documentation...


We're not surrounded, we're in a target-rich environment!
Re^2: File upload probelem
created: 2006-04-05 09:22:03
thanks for the suggestion, it appears to be a form problem.

perlmonks.org content © perlmonks.org and Anonymous Monk, jasonk

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03