fuelphp / upload

FuelPHP Framework - File upload library
MIT License
26 stars 16 forks source link

Problem with upload. #19

Closed lshaf closed 7 years ago

lshaf commented 7 years ago

I always got message "Unable to move the uploaded file to it's final destination" when I upload Here is my code

$config = array(
          'auto_process' => false,
          'path' => $path,
          'overwrite' => true,
          'new_name' => "tmpcsv_teacher",
          'auto_rename' => false,
          'ext_whitelist' => array('csv'),
        );
        Upload::process($config);
        if (Upload::is_valid()) {
          Upload::save();
        }
        if ($file_upload = Upload::get_files(0)) {
          $filename = $path.'/'.$file_upload['saved_as'];
          $uploaded = true;
        }
        $errors = Upload::get_errors(0);
        echo '<pre>';var_dump($errors);exit;

I'm using latest version 2.0.6 and my folder is 770 My PHP is version 5.6/ I have no idea about this, I didn't found any threat on internet about this 😖

WanWizard commented 7 years ago

It means http://php.net/manual/en/function.move-uploaded-file.php returned FALSE. There could be several reasons for that, so you have to do some debugging.

You say the folder is 770, but what are the UID/GUID of the folder? If either of them is your webserver user, the webserver doesn't have write rights.

lshaf commented 7 years ago

[SOLVED] Nah, it seems the main problem isn't there. however my uploaded file has been processed for twice and it make upload container contain 2 same files. Because of that, when I move the first array it's success but the second one is fail. that's caused the error.

I just fix it by turn of "auto_process" on config/upload.php

WanWizard commented 7 years ago

Yup, when auto_process is active, you shouldn't call Process() manually. This behaviour is documented: https://fuelphp.com/docs/classes/upload/usage.html#/method_process

lshaf commented 7 years ago

Well, since I use my own config on there. I think I have no reason to write it again on file config 😕

       $config = array(
          'auto_process' => false,
          'path' => $path,
          'overwrite' => true,
          'new_name' => "tmpcsv_teacher",
          'auto_rename' => false,
          'ext_whitelist' => array('csv'),
        );

btw Is there any reason that you make 'auto_process' when I init upload data by calling process? I just feel like it's no sense when you call "Process" to init the upload but you do that "Process" again.

WanWizard commented 7 years ago

Not a problem, just make sure "auto_process" is disabled.

It is enabled by default for backward compatibility reasons, the package is used in the Fuel v1 framework as well, and there this behaviour was default.