Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload w/ new name
  • hello
    I want to ask about upload,
    when I upload file and I want to save it with a new name in my server, that always fail. the filename in my server still same with the local.

    this is my code


    $config = array(
    'auto_process' => false,
    'path' => DOCROOT.'assets/img/photo',
    'max_size' => 1024000,
    'overwrite' => true,
    'new_name' => 'my_pic',
    'auto_rename' => false,
    'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
    );
    Upload::process($config);
    if(Upload::is_valid()){
    Upload::save();
    }
    if($file_upload = Upload::get_files(0)){
    $filename = $file_upload['saved_as'];
    }
    $errors = Upload::get_errors(0);
    new_name doesn't work, do you have solution?
    sorry if my english is poor
  • HarroHarro
    Accepted Answer
    Assuming you're on 1.6:

    Update your Upload composer package, this has been fixed recently (July 16th to be exact).
  • Hi, I'm having the same problem, but I'm not familiar with composer. I have run both `self-update` and `update` so now composer reports that there is nothing new to install. However, I can check that in the vendor folder, I still have older versions of the Upload package. How do I tell composer to get the latest files from the Upload repository?

    Thanks
  • check in your composer.json which version is speficied. It should say "dev-master".
  • I see. My version was set to "2.0". However, dev-master requires php >= 5.4. Is there a way around that requirement? Unfortunately, my target environment is running php 5.3 and I'd rather not go through the pain of potentially breaking other software on it just to get the uploaded filenames correct.

    I ended up just cherry picking the relevant commit by hand into my Upload/Upload.php and Upload/File.php and it works fine.

    Thanks for your help, though!
  • Problem is that Upload is a Fuel 2 library, and Fuel 2 is PHP 5.4+.  Upload itself doesn't really have that requirement.

    We have to figure that out for the time we're running 2.0 libraries in the 1.x codebase.
  • Hello,
    I try to upload a file and it works.Cool.
    But i would like to rename the file. I found a option for $config : new_name.
    The file is upload on the server with this name, but Upload::get_files() return an array. The attribute "name" is the filename, not the new_name.
    The attribute "saved_as" is the news name, but not normalize. I don't want a space for exemple.

    Is it normal ? how could I normalize the file uploaded et get the name of this file normalized ?

  • If you define a new name, it will be saved with this new name.

    If you want to execute runtime operations of the filename (or other options), you will have to use a "before" callback (if you are using the Fuel Upload class) or a "before_save" callback if you use the Upload package directly.

    There is an example of tha "before" callback in the docs.

Howdy, Stranger!

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

In this Discussion