\Image File not found

115 views
Skip to first unread message

AM

unread,
Oct 14, 2016, 12:07:55 PM10/14/16
to Fat-Free Framework
Hey,

I´m trying to work with an uploaded Image:

$img = new \Image( $_FILES['avatar']['tmp_name'] );
$img->resize( 300, 300 );
$f3->write( $avatar_filename, $img->dump('jpg',50) );

But I get a FILE NOT FOUND error:
Image->__construct('E:\xampp\tmp\php8362.tmp')

When I try like this it works
move_uploaded_file($_FILES['avatar']['tmp_name'], "content/img/" .$avatar_filename);

What´s wrong with my F3 code?

Thanks!

ikkez

unread,
Oct 15, 2016, 5:06:01 AM10/15/16
to Fat-Free Framework
I think this is normal behaviour in php. it does not allow to procees files within the tmp folder. you need to move the uploaded file first.

Summer White

unread,
Oct 15, 2016, 5:25:31 AM10/15/16
to Fat-Free Framework
This code below is from an application I'm working on. Feel free to pick it apart a little bit. I ran into the exact same problems you had.

Please take note of this comment. It explains your issue exactly.
        // Pull image off the disk into memory
        $temp_image
= new Image($image, false, "/");


    function upload($f3) {

        $upload_path
= setting($this->namespace."_image_directory");
        $thumb_path
= setting($this->namespace."_thumb_directory");

       
// Temp image path
        $temp_image
= $f3->FILES["file"]["tmp_name"];

       
// New name
        $new_name
= str_replace(' ', '_', $f3->FILES["file"]["name"]);
        $new_name
= filter_var($new_name, FILTER_SANITIZE_EMAIL);

       
// Where to save the full image too
        $save_to_full
= getcwd()."/".$upload_path."/".$new_name;

       
// Where to save the thumb too
        $save_to_thumb
= getcwd()."/".$thumb_path."/".$this->thumb_prefix.$new_name;

       
// Get settings for image size
        $image_size
= setting($this->namespace."_image_size");
        $thumb_size
= setting($this->namespace."_thumb_size");

        $image_size
= explode("x", $image_size);
        $thumb_size
= explode("x", $thumb_size);

       
// Resize full image and save
       
if ($image_size[0] > 0 && $image_size[1] > 0)
            $this
->resize_image($temp_image, $image_size[0], $image_size[1], $save_to_full);
       
// If no image size set, just move image
       
else
            copy
($temp_image, $save_to_full);

       
// Resize thumbnail image and save
       
if ($thumb_size[0] > 0 && $thumb_size[1] > 0)
            $this
->resize_image($temp_image ,$thumb_size[0], $thumb_size[1], $save_to_thumb);
       
       
// If thumbnail settings are not set just resize as image size
       
else if ($image_size[0] > 0 && $image_size[1] > 0)
            $this
->resize_image($temp_image, $image_size[0], $image_size[1], $save_to_thumb);

       
// If image settings not set lets just copy the raw file
       
else
            copy
($temp_image, $save_to_thumb);
   
       
// Record into database
        $f3
->DB->exec("INSERT INTO {$this->namespace} (filename, `order`, caption)
                       VALUES (?, ?, ?)"
, [$new_name, 0, '']);

   
}

   
function resize_image ($image, $x, $y, $save_as) {

       
// Pull image off the disk into memory
        $temp_image
= new Image($image, false, "/");

       
// Resize image using F3's image plugin
        $temp_image
->resize($x, $y, false, false);
       
       
// Save image    
        imagejpeg
($temp_image->data(), $save_as);
   
}

AM

unread,
Oct 17, 2016, 5:46:31 AM10/17/16
to Fat-Free Framework
for me, this worked:

$img = new \Image( $f3->FILES['avatar']['tmp_name'], false, '' );

$img->dump('jpeg',50);
also threw an error: 
imagejpeg(): Invalid 2nd parameter, it must a filename or a stream

So I also went with using imagejpeg() directly

thanks!
Reply all
Reply to author
Forward
0 new messages