Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
file upload, save under different name
  • when uploading a file using Upload:: , is there a way to save the file under a different name that I can specify? ( not necessarily a random number)
  • so far what I found is that one can use
    Upload::process(array(
    'prefix'=> ' ',
    'randomize'=> true,
    'suffix'=>' ',
    ))
    which is good enough for what I wanted to do
    hope this helps someone
  • Register a "before" callback, it gives you access to the 'saved_to' and 'saved_as' fields of the file array, and allows you to alter both path and name before saving. You can also use the "after" callback, have the Upload class save it to a random filename, then access that name in your callback method, and move the file elsewhere.
  • Harro Verton wrote on Sunday 19th of June 2011:
    Register a "before" callback, it gives you access to the 'saved_to' and 'saved_as' fields of the file array, and allows you to alter both path and name before saving. You can also use the "after" callback, have the Upload class save it to a random filename, then access that name in your callback method, and move the file elsewhere.

    Do you happen to have an example for that by any chance? I would greatly appreciate it. my code looks like this
     Upload::process(array(
             'prefix'=> Session::get('user_id').'_',
               
            ));
            
            Upload::get_files();
            
                if (Upload::is_valid()) {
                
                 Upload::save();
    
    }
    
  • There's an excellent example in the docs, using a closure so you don't have to define the actual callback method. The example alters the path to save to, but you can do any manipulation of the file array.

Howdy, Stranger!

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

In this Discussion