I'm writing a CGI-Script that's supposed to do something very simple that I've done a few times before: Upload an image and save it on the webserver. Here's what I got:
sub handle_image { my $id = shift or die "Internal Error\n"; my $image = param ('image'); my $filename = ''; if ($image) { $filename = '/images/' . $id . '.jpg'; open (IMAGE, '> ..' . $filename); while (my $bytestoread = read ($image, my $buffer, 102 +4)) { print IMAGE $buffer; } close IMAGE; } elsif (-e '../images/' . $id . '.jpg') { $filename = '/images/' . $id . '.jpg'; } return $filename; }


As you see the routine checks for data to save or, if no data available, for an existing image and returns the filename.

The odd thing is, that this script works fine on my local workstation, but not on the webserver. $image holds the filename of the image, but the filehandle (<$image>) is empty. And yes, I'm using enctype="multipart/form-data" and the directory is writeable for the webserver. It creates a new but empty file.. I've checked all nodes about CGI.pm and file uploading but I couldn't find an answer.
Are there any differences between different versions of CGI.pm or perl that might cause that problem?

Regards,
octopus
--
GED/CC d-- s:- a--- C++(+++) UL+++ P++++$ L++>++++ E--- W+++@ N o? K? w-- O- M-(+) V? !PS !PE !Y PGP+(++) t-- 5 X+ R+(+++) tv+(++) b++@ DI+() D+ G++ e->+++ h!++ r+(++) y+

In reply to strange CGI.pm behavior by flocto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.