*alexandre* has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I cannot figure out why the Following code doesn't work withing Windows 10
#!"C:\xampp\perl\bin\perl.exe" use CGI; use Image::Thumbnail; my $imgdir= "C:/Users/41786/Documents/recordz1/upload"; my $query = new CGI; uploadImage('testFileUploadAndThumb.jpg'); sub uploadImage { my $name = shift || ''; my $file = $query->param('image'); open(LOCAL, ">$imgdir/$name.jpg") or print 'error'; my $file_handle = $query->upload('image'); + binmode LOCAL; while(<$file_handle>) { print LOCAL; } close($file_handle); close(LOCAL); createImageMagickThumb("$name"); } sub createImageMagickThumb { my $filename = shift || ''; my $t = new Image::Thumbnail( size => 55, create => 1, input => '$imgdir/$filename', outputpath => '$imgdir/test.$filename', ); print "Content-Type: text/html\n\n"; print "outputpath => '$imgdir/test.$filename'"; }
It upload the image well but the thumbnail is not created, any idea ?? THx

Replies are listed 'Best First'.
Re: Image::Thumbnail not created
by holli (Abbot) on Jul 12, 2019 at 13:52 UTC
    input => '$imgdir/$filename', outputpath => '$imgdir/test.$filename',
    Double quotes, anyone? Also, you're not passing the extension into the thumbnail function, only the basename of the file.


    holli

    You can lead your users to water, but alas, you cannot drown them.
      Thx ;-)
Re: Image::Thumbnail not created
by hippo (Archbishop) on Jul 12, 2019 at 13:40 UTC
Re: Image::Thumbnail not created (updated)
by AnomalousMonk (Archbishop) on Jul 12, 2019 at 14:15 UTC
    open(LOCAL, ">$imgdir/$name.jpg") or print 'error';

    Nothing to do with the immediate problem, but this statement in  uploadImage() is problematic: if there is some vague 'error' and the file fails to open, execution will continue (briefly | see Update below) with an undefined | a closed filehandle. See haukex's "open" Best Practices.

    Update: I thought that some kind of fatal exception would be thrown in a subsequent statement if the open failed, but not so: execution will continue indefinitely with a closed filehandle, and not even warning messages will be generated if warnings is not in use!


    Give a man a fish:  <%-{-{-{-<