Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Upload Multiple Files
  • Hi,

    I am building a very small app - loosely based on one I found on Github - as a way to learn Fuel and hone my general PHP skills.

    Currently, I have a form & I'm able to upload 1 Image & store the file name in my database - woop!
    // Custom configuration for this upload

    $config = array(
        'path' => DOCROOT.DS.'images',


        'randomize' => true,
        'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'),
    );

    Upload::process($config);

    if (Upload::is_valid())
    {
        Upload::save();
        $value = Upload::get_files();
        $article->filename = $value[0]['saved_as'];
    }


    However, I’d now like to loop through multiple images.

    How would I do this?

    I'm guessing once it comes to the Model (database) I'll need to create a new Table solely for Images. Right now, I'm just using a 'saved_as' column in my main table.

    Thanks for any advice here :-)
  • HarroHarro
    Accepted Answer
    As you noticed, $value is an array, it has an entry for each file uploaded (that is saved succesfully). Just loop over it.
  • Ooooh, very good call.

    Sorry to be a bit dense, but where should I add my loop?

    Should I loop this entire area:

    if (Upload::is_valid())
    {
        Upload::save();
        $value = Upload::get_files();
        $article->filename = $value[0]['saved_as'];
    }
    ?
  • Assuming you have multiple files uploaded, you will have an entry in $value for each of the files.

    Which also means you probably need a way to store multiple file names in your article. I can't see what $article is so I can't be more specific at this point.
  • Aaaah OK.
    This is $article >> $article = Model_Article::forge();

    I will run a foreach loop on the code portion I posted above & give it a try - thanks for the help so far :-)

Howdy, Stranger!

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

In this Discussion