Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Working with images
  • Hello!

    Can you describe the full way of working with images.from <input type="file"> to saving the image in the folder. Will it be enough to use Image class or I should use Upload class too.

    Or, please, put an example here.
    Thank you very much!
  • You need to Upload class to processing the form upload. You need the Image class if you want to manipulate the image after uploading.

    There's an example in the docs on how to process uploads: http://docs.fuelphp.com/classes/upload/usage.html#/usage_example
  • ErrorException [ Error ]: Call to undefined function Fuel\Core\finfo_open()

    COREPATH/classes/upload.php @ line 344


    When I click to go to this function - me IDE (phpstorm) finds it.

    Tell me please, what is this exception about (how can I solve it).
    If you need a part of my code - I'll give you with no problem.
  • Your working on a PHP installation that is not according to the standards. PHP 5.3+ should have the finfo module installed by default. If this is locally, you should fix your installation. If this is a hoster, kick him in the nuts for not providing a standard installation.

    If you're on Windows, you need to activate the finfo dll in your PHP config, it's not added by default.

    This requirement is documented here: http://fuelphp.com/docs/requirements.html
  • Yes, I'm working on a local Windows and your answer (as usually) helped me to solve this problev. Thank you very much.

    If you don't mind, I'll continue this thread :)

    If I have many fields of file upload, what is the logic of their processing?
    I found http://fuelphp.com/docs/classes/upload/usage.html#/method_get_errors the statement here about
    Upload::UPLOAD_ERR_NO_FILE , but will it be correct if I write

    if (!Upload::UPLOAD_ERR_NO_FILE)
    {
    //foles processing
    }

    or I should make another "if" to check this point?
  • HarroHarro
    Accepted Answer
    Assuming you have setup your configuration correctly, the first thing you do is run Upload::process().

    After that, you can call Upload::get_errors(), to see if there were any processing errors. This call returns an array with an array for every file uploaded, and all information about the file, including all detected errors.

    If you don't have any errors, continue by calling Upload::save(). Again, after this call get_errors() so see if you had any errors while saving the uploaded files.

    Just play a bit with it, do some var_dumps to check what data is returned, to get a feel for how it works.

    p.s. It's pretty pointless checking the value of a constant in an if. :-)
  • p.s. It's pretty pointless checking the value of a constant in an if. :-)

    It's true... I'm pretty stupid :)

    Meanwhile something turns well, so your answer as olways on top
  • One simple question. Image was uploaded. I want to resize it and put resizet copy to another folder (origin file must be saved). Please, tell me how to do it. For resizing - class Image. Should I use for copy File class or there is possibility in Image class to save new image in another folder?
  • I've never used the Image class myself, but the load() method in the docs gives an example with Upload.
  • Yes... I've already used this example... and everithing is all right with images saving and procesing... But now again trouble with table relations.

    UPD... I deleted an example, because trouble was solved. Thank you very much.

Howdy, Stranger!

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

In this Discussion