Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload: Odd behavior when saving file upload
  • Hello!

    I have trying to upload image files to a directory in my home dir: /home/user/uploads.

    "uploads"' has not write permission and hence upload should fail but... I have struggled with an odd behavior when saving files.
    Upload::save() do not returns anything about the operation status (ok, it's documented) and hence I can't .parse any errors.

    My question is: Is there a way that I can catch "UPLOAD_ERR MOVE FAILED" error?

  • Also, I've found other weird issue:
    When registering callbacks to events I have noticed that Upload::geterrors() returns a populated array as expected. Like this: 

        function upload() {
            $config = $this->uploadconf();       
            upload::register('after', function(&$file) use ($config) { 
                # WTF, Fuel!?
                /* this callback acctully does anything but if it exists, 
                Upload::get_errors works like  a charm! (very odd behavior...)*/
            });

            Upload::process($config);

            if (Upload::is_valid()) {           
               Upload::save();              
               var_dump('UPLOAD ERRORS: ', Upload::get_errors('uploaded'));             
            } 
        }


     However if I not register an upload event callback - like following snippet - Upload::get_errors() returns an empty array. Like this: 

        function upload() {
            $config = $this->uploadconf();      
            Upload::process($config);

            if (Upload::is_valid()) {           
               Upload::save();              
               //Upload::get_errors('uploaded') returns a empety array 
               var_dump('UPLOAD ERRORS: ', Upload::get_errors('uploaded')); # so sad...    
            } 
        }


     That's so weird... so weird... 
    I have developing with fuelphp v 1.7.2.


    Thanks in advance!
  • Very odd, because the after_save callback is only called if there wasn't an error. And even if the callback was called, it requires an instance of FileError to be returned to add an error.

    Can you post your entire upload config, so I can test it here? And what exactly are the rights on the upload folder? read-only? or none at all?
  • Hi, Harro!

    I just made a screencast about the issue, follow: http://youtu.be/ijlKJDRoG-o



    Many thanks, Harro!


  • HarroHarro
    Accepted Answer
    Your Upload package isn't up to date.

    Change the version in the composer.json to "2.0.2", and run a composer update to fix it.

    When you have issues like this, try switching to the latest develop version first, to check if the issue hasn't been solved, before reporting it.
  • Hi, Harro!

    So it was a bug.

    Updating fuelphp/upload package v2.0.1 to v2.0.2 has fixed! It works right now!


    Many thanks, again!

Howdy, Stranger!

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

In this Discussion