Upon further testing I verified that the statement
"my $picture = $query->upload("$file");"
is indeed returning undefined.

What would cause that?
I do know that $file DOES contain valid information (the correct name of
the field holding the file to be uploaded).

--Alex

>
>     Thanks Richard, everyone.  I tried your (Richard) code also.  It bombs
> on "No File Specified".  Looks like somehow it can't grab ahold of the
> file I'm trying to upload.  There must be something in the rest of my
> cod that is interfering with all this.  But I really can't imagine
> what.  The rest of my code is truly very simple.  I decided to try
> once more with some of my original upload code (which DOES work on a
> simpler version of this app I'm creating).
>
> I know this might not be the prettiest thing around..., but here is an
> example of the code I'm using to take in one of the pictures:
> # Checking if you submitted a front side of a web-friendly picture.
> if ($query->param('webFront')) {
>       #Take in the field's value.
>       $webFrontPic = $query->param('webFront');
>       #Do the actual uploading...
>       &UploadPicture($photoID, $webFrontPic,'webFront');
>       print "Selected $webFrontPic to be uploaded as the web front<br>\n";
> }else {
>       &Error("No Web Friendly front side picture was submitted");
> }
>
> Again, here is the code I am now using for the upload function:
> sub UploadPicture {
>
>       my $photoID = $_[0];
>       my $file = $_[1];
>       my $picLoc = $_[2];
>
>       my $filepath = "$UPLOAD_DIR/$picLoc$photoID$file\.jpg";
>
>       $upload_filehandle = $query->upload($file);
>       open UPLOADFILE, ">$filepath";
>       while ( <$upload_filehandle> )  {
>               print UPLOADFILE;
>       }
>       close UPLOADFILE;
>
> }
>
> ..........ideas?........
>
> --Alex
>
>> Here is some code I've written that does work...  It's using CGI.pm.
>> What follows is short snippets of the code, not the whole thing...
>>
>> at the start of the file:
>>
>> #!perl
>> use strict;
>> use warnings;
>> use CGI;
>> use CGI::Carp qw/fatalsToBrowser/;
>>
>> my $q = new CGI;
>>
>> later on, I create the form:
>>
>> <form method="post" action="/path/to/script"
>> enctype="multipart/form-data">
>> File to upload: <input type="file" size="40" name="data"><br />
>> <input type="submit" value="Upload file">
>> </form>
>>
>>
>> then, I use the following code to retrieve the file:
>>
>> # first, we need to grab the uploaded file's file handle, and check
>> # to see if there was an error during the send....
>> my $fh = $q->upload('data');
>> if (!$fh and $q->cgi_error) {
>>      die("File upload error: " . $q->cgi_error);
>> } elsif (!$fh) {
>>      die("No file specified");
>> }
>>
>> my $fname = "output_file";
>> # at this point, we have a good file that has been uploaded....
>> open(my $out, ">", "$WORKING_DIR/$fname") or die("Could not create
>> file: $!");
>>
>> # we make sure that we have raw character discipline
>> binmode($fh, ":raw");
>> binmode($out, ":raw");
>>
>> # now, read the data using buffered IO
>> my $bytesread;
>> my $buffer;
>> while($bytesread = read($fh, $buffer, 1024)) {
>>      print $out $buffer;
>> }
>>
>> # read returns undef on an error.  I don't know where this error gets
>> stored
>> # but I'm guessing $!
>> if (!defined($bytesread)) {
>>      die("An error occured while trying to write the file: $!");
>> }
>>
>> # now close the files...
>> close($fh) or die("couldn't close uploaded file: $!");
>> close($out) or die("couldn't close copied file: $!");
>>
>>
>> you can obviously modify this code as needed, but it looks fairly close
>> to what you need.
>>
>> Hopefully, people won't find that I've made too many ugly mistakes, or
>> forgotten to check some important return codes (although if I have,
>> please let me know...)
>>
>> HTH,
>> Ricky
>>
>
> _______________________________________________
> Boston-pm mailing list
> [EMAIL PROTECTED]
> http://mail.pm.org/mailman/listinfo/boston-pm
>

_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to