OK, I believe I identified the source of the problem, even though I don't 
yet understand it:
somehow the filehandle for reading the input file is not set properly.

As I understand it, the filehandle should be the local filename (hence 
"$file" in the code given below), but if I just use "$file", it doesn't 
work.
If I use CGI.pm's "upload" function, the filename is obtained properly:
my $q = new CGI;
my $filehandle = $q->upload(param("imagefieldname"));

Using $filehandle instead of $file in the code below does a proper upload.

But this only works when the image is uploaded via a form field.
What I would like to do, however, is to parse content of a textarea field 
for image names and then upload all of them, so there will be no such 
field.

The only workaround I can think of is to use Javascript to create form 
values for images on submit, but isn't there a simpler, perl-ish solution?

--On Donnerstag, 13. Dezember 2001 17:01 +0100 Birgit Kellner 
<[EMAIL PROTECTED]> wrote:

> I'm trying to code a routine for uploading up to four images via a
> CGI-form, using CGI.pm.
>
> Filenames including local paths are stored in @files_to_upload.
> At this point in the script I have the base names of each file in
> @files_to_uploaded associated with the full filename in %basename, and
> the extension in %imageextension. I separated these because I wanted to
> validate the extensions and the filenames before the files are uploaded.
>
> $imagepath is the server path to the image directory.
>
> With the code given below, the appropriate files are created on the
> server, but nothing is written to them.
>
> foreach my $file (@files_to_upload) {
>       my $filename = "$basename{$file}" .
> "\.$imageextension{$basename{$file}}";        my $newfilename =
> "$image_path\/$filename";
>       print "TESTING - FILE: $file, FILENAME: $filename, NEWFILENAME:
> $newfilename<br>";# prints ok         my $bytesread;
>       binmode (OUTFILE);
>       open(OUTFILE, ">$newfilename") || die ("Cannot write to $newfilename:
> $!");             while ($bytesread = read($file,$buffer,1024)) {
>                       print qq|yep!|;# doesn't get printed
>                       print OUTFILE $buffer;}
>                       close ($file);
>                       close (OUTFILE);
>                       print qq|BYTES read: $bytesread<br>|;# no value for $bytesread
> }
>

Birgit Kellner

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to