Multiple File Uploads

edited January 2011 in Modules
I am looking for some direction on uploading many files at once and creating a photo item for each file. I already have a 'photos' module and an 'albums' module.

I know about the 'multifile' class that I can add to an upload field. The problem comes down to having to add a photo item individually in order to put it into an album. It is rather tedious and I would like my client to be able to add multiple photo items at one time.

Comments

  • edited 2:25PM
    Are you referring to opening up a single window and being able to select multiple files at once to upload? If so, that, unfortunately, is not supported out of the box at the moment and would require some extra coding on your part. It does look like both Safari and Opera natively support that, but for other browsers, it may require using the Flash file uploader (from what I remember the options to be). If you were wanting to build it in, you would probably need both a custom javascript file that uses one of those Flash multifile plugins and one of the model hooks to process it. Also, the CodeIgniter Upload class doesn't natively support multiple files which is what we are using, however, I did find a forum link that may help us to work in support for that.

    All that said, I've put it on the list of features to look at for upcoming releases.

    http://blog.observationpoint.org/post/169674727/multiple-file-upload-support-in-safari-4-public-beta
    http://codeigniter.com/forums/viewthread/110130/
  • edited 2:25PM
    I've mulled it over a bit more and I think my best solution would be to not use Flash.

    I'm thinking:

    - A module with an upload field with the 'multifile' class.
    - Upon submission of the form a loop adds each file as a row to the 'photos' table.

    Last night, though, I was not able to get the multiple file array. Going to start playing with it to see what I can come up with.
  • edited January 2011
    Alright. This may be a little sloppy but it's working fine:
    	function on_after_save($values)
    {
    for ($i=0; $i < count($_FILES); $i++) {
    $this->photos_model->insert(array('large_img'=>$_FILES['large_img_upload___'.$i]['name'], 'name' => $values['name'].' '.$i));
    }
    }
    Takes the $_FILES array and adds each item as a row in the appropriate table.

    Thoughts on my solution?
  • edited 2:25PM
    Nice work. I would maybe put checks to make sure their isn't an error for the file uploaded, but otherwise, that should do it. The on_after_post hook can be used if you need to process the image in any way on the server first.

    As an FYI, the file fuel/modules/fuel/controllers/module.php has a method of _process_uploads() (near the bottom), that has the logic for processing file uploads if you want a reference.
Sign In or Register to comment.