Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Am I missing something?

Status
Not open for further replies.

williamu

Programmer
Apr 8, 2002
494
GB
Hi All,

I have the following code:
Code:
 sub SaveAttachment
 {
      my $Success = 0 ;
      my $fh = $CGI->upload("MyPrint") || undef ;
      my $fn = sprintf("%lX.jpg", time()) ;
      my $File = sprintf("%s/%s", UPLOAD_DIR, $fn) ;
      if ($fh)
      {
          $Tmp->param(FileName => $fn) ;
          my ($Bytes, $Buffer) = (0, '') ;
          sysopen(FILE, $File, O_WRONLY | O_CREAT | O_EXCL ) or die "Error : $!\n" ;
          while ($Bytes = read($fh, $Buffer, BUFFER_SIZE))
          {
              print FILE $Buffer ;
          }
          close (FILE) ;
          $Tmp->param(eMail => $File) ;
          open(IMAGE, '<$File') or die "Unable to open $File because: $!\n" ;
          my $FileSize = $Img->Read(file => \*IMAGE) ;
          warn "$FileSize" if "$FileSize" ;
          $Tmp->param(FileSize => $FileSize) ;
          close (IMAGE) ;
          $Success = 1 ;
          }
     return $Success ;
}
Which saves the file as expected however, what it doesn't do is open it again as it dies saying there is "No such file or directory". How can this be when the file is there on the disk?

If this section of the code is commented out the uploaded image appears in the browser as expected, so this only serves to add to the confusion.

I guess I must be missing something obvious but as to what it is I have no idea, can any one help me here?

--
Thanks.
 
looks like the single quotes are killing the variable interpolation here:

open(IMAGE, '<$File')

change to double-quotes:

open(IMAGE, "<$File")
 
Hey, now that's an impressive response time. Thanks.
Ok, the " qoutes now works but results in this:

Exception 435: unable to write blob `/tmp/magick-LAe12710': Bad file descriptor.

but there may not be any ImageMagic guys here, is there?

Thanks again.
 
Hi audiopro,

In answer to your question BUFFER_SIZE is a constant defined as 8192. But in this instance is quite redundant as the image is saved to disk as expected.

--
 
thats what I thought too, but I threw in "maybe" in case it was a constant.
 
I think I've only used Image::FileSize to get image sizes myself... although I do like the stand alone progs in the Image Magick package =)

Kordaff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top