Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Need help using the Upload Class
  • My requirement is to upload a PDF file to a specific location on the server. The PDF file will be selected using a file input field. I have created a view with a file input field and in the controller I have added the following code which gets fired when the form is submitted but the files array is displayed as empty. $files = Upload::get_files();
    print_r($files); I am new to fuelphp, therefore please give me some pointers on how to get this working.
    Thanks.
  • You will need to process your uploaded files first, using Upload::process(). This will validate all uploads, and process all successful uploads according to the configuration. After that, you can call get_files() to get all valid files, and get_errors() to get all invalid files. Use save() to save all valid files to their final destination, depending on the configuration.
  • I have already tried using Upload::process but still the $files array shows up as empty. Upload::process(array(
    'path' => './uploads',
    'normalize' => true,
    'change_case' => 'lower'
    )); $files = Upload::get_files();
    print_r($files);
  • do you have the
    enctype="multipart/form-data"
    in the <form> tag?
  • Or errors in the processing? get_files() only returns the uploaded files that are valid, get_errors() the ones that are rejected.
  • I've added a usage example to the Upload docs (in the develop branch).
  • Chris P wrote on Thursday 23rd of June 2011:
    do you have the
    enctype="multipart/form-data"
    in the <form> tag?

    Thanks for all the help! The above did the trick for me! I am now able to upload the files without any issues.

Howdy, Stranger!

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

In this Discussion