Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to upload , resize and save an image
  • I am a bit confused as to how to exactly How to upload , modify and save an image. if I am correct, I must use the upload class to upload the file then use the Image class to load , modify the image then save it Please correct me if i am wrong in this logic it would be also great if i can get a rough idea as to how to proceed with this logic I have also tried loading an image from the server in order to modify it and save it but had little success when i do this : $image=Image::factory(array('quality' => 80)); $image->load("photos/user/1910_1291778441_432224420.png",true); i get the following error : Fuel\Core\Fuel_Exception [ Error ]: The library does not support this filetype for .....
    thank you for your help
  • No, develop is a different branch. If you don't use git, you can download it at https://github.com/fuel/core/zipball/develop. otherwise go to the core directory, and type 'git checkout develop' to switch to the develop branch.
  • Thanks :)
  • I have tried the latest dev branch but I still get : Fuel\Core\Fuel_Exception [ Error ]: The library does not support this filetype for /Applications/MAMP/tmp/php/phptFpXeU
    I later on upgraded to Rc3 but the problem still persists.
    your help is greatly appreciated ps: i might be off here but I believe the problem is with the file path I am using which is : $file
  • The image driver does an extension check to see if the filetype is valid. Since your file doesn't have an extension, the check fails and bails out with this error.
  • So I got it working ( though I cant guarantee this is the best way to do things).I hope this helps someone : // sets prefix to the name of the file & turn the name into a random string
     Upload::process(array(
             'prefix'=> Session::get('user_id').'_',
                    'randomize'=> true,
        
            ));
    
    // get the file and if the file is valid save it
            Upload::get_files();
            
                if (Upload::is_valid()) { Upload::save();}
    
    // The upload function works with arrays ( multiple uploads possible) which is why i use foreach to process any image uploaded
      $files = Upload::get_files();
    
      foreach( $files  as $key=>$file ) {
    
    // getting the full path of the file
      $filepath=$file['saved_to'].$file['saved_as'];
    
    // if you wanna resize the image for example
                    $width=640;
                   $height=480;
      
      Image::factory()->load($filepath) ->resize($width, $height) ->save($filepath);
    
    }
    

    feel free to reply here if you have any questions, I will do my best to answer them.
  • Salmane S wrote on Thursday 26th of May 2011:
    I am a bit confused as to how to exactly How to upload , modify and save an image. if I am correct, I must use the upload class to upload the file then use the Image class to load , modify the image then save it Please correct me if i am wrong in this logic it would be also great if i can get a rough idea as to how to proceed with this logic I have also tried loading an image from the server in order to modify it and save it but had little success when i do this : $image=Image::factory(array('quality' => 80)); $image->load("photos/user/1910_1291778441_432224420.png",true); i get the following error : Fuel\Core\Fuel_Exception [ Error ]: The library does not support this filetype for .....
    thank you for your help

    Hello,it works smth like this; http://scrp.at/0Y
    but make sure you running the DEVELOP branch from fuel/core, because image had been greatly updated more info inside docs: http://fuelphp.com/docs/classes/image.html
  • Thank you very much.
    I will check it out right away!
  • Just to make sure the "DEVELOP branch" of the core is the same as RC2.1 or not? I updated to it and I am trying to upload an image through a form I past the image file array to the image class like this : $image=Image::factory($config);
    $image ->load($file) ; i get the following error : Fuel\Core\Fuel_Exception [ Error ]: Image file does not exist.
    COREPATH/classes/image/driver.php @ line 128 any ideas?
  • Cheers mate, can I see what is your code in app/config/image.php tnx :)

  • Note that this is a 6 your old thread, with code from Fuel v1.1 that no longer works. 

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion