Update: Sorry - I was half asleep and did not read the question properly. I'll leave the code all the same

Old and untidy code :( I've trimmed out some parts (checking if file of same name already exists, for example)

sub upload_file { my $upfilename = $q->param('filebrowser'); $upfilename = (split(/\\/, $upfilename))[-1]; my $upfile = $q->upload('filebrowser'); if (!$upfile && $q->cgi_error) { print $q->header(-status=>$q->cgi_error); } else { $filepath = "$images_directory/$upfilename"; open (NEWFILE, ">$filepath") or &error_code("Could not save to + $filepath"); binmode NEWFILE; my ($mbytesread, $mbuffer, $mBytes); while ($mbytesread = read($upfile, $mbuffer, 1024)) { $mBytes += $mbytesread; print NEWFILE $mbuffer; } close(NEWFILE); if ($mBytes <= 0) { &error_code("Uploaded file is 0 bytes in size and will be +discarded."); unlink $filepath; } # create thumbnail use GD; use Image::GD::Thumbnail; # Load your source image open (IN, "<$filepath") or &error_code("Could not open $filepa +th to create thumbnail"); my $srcImage = GD::Image->newFromJpeg(*IN); close(IN); # Create the thumbnail from it, where the biggest side is 200 +px my ($thumb,$x,$y) = Image::GD::Thumbnail::create($srcImage,200 +); # Save your thumbnail open (OUT, ">$thumbs_directory/$upfilename") or &error_code("C +ould not save to $thumbs_directory/$upfilename"); binmode OUT; print OUT $thumb->jpeg; close(OUT); }

In reply to Re: Creating GD::Image directly from CGI->upload() by hostyle
in thread Creating GD::Image directly from CGI->upload() by saberworks

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.