View Looks Like This
<?=form_open_multipart('upload/process');?>
<input type="file" multiple="multiple" name="userfile[]" id="userfile" />
<?=form_submit('upload', 'Upload');?>
<?=form_close();?>
i want the user to be able to upload multiple images at once. once uploaded i want to make an entry of the image details in the database, and finally move the image to the uploads folder.
i have basic knowledge of codeigniter
ps: i dont want to use uploadify or similar image uploading plugins. trying to keep it as light weight as possible
Update this is the kind of array i am getting when i try var_dump($_FILES['userfile']). what kind of loop should i use to separate the data of the respective images.
array
'name' =>
array
0 => string '01.jpg' (length=6)
1 => string '1 (26).jpg' (length=10)
'type' =>
array
0 => string 'image/jpeg' (length=10)
1 => string 'image/jpeg' (length=10)
'tmp_name' =>
array
0 => string 'C:\wamp\tmp\php2AC2.tmp' (length=23)
1 => string 'C:\wamp\tmp\php2AD3.tmp' (length=23)
'error' =>
array
0 => int 0
1 => int 0
'size' =>
array
0 => int 409424
1 => int 260343
The loop you need:
Note that is doesn't use the CI upload class, but plain PHP, which I usually find easier to work with instead of the CI's class.
I ran into this problem aswell. The
$_FILES
data is sent a diffent structure (due to themultiple=""
attribute) so codeigniter can't handle it. Prepend this before the uploading process:Then in the loop function use this:
Explanation:
I simply change the structure of
$_FILES
to the common structure which is sent on a default<input type="file" />
and the run a loop, fetching all their key names.Check out this class for multiple file upload https://github.com/stvnthomas/CodeIgniter-Multi-Upload
This did the trick for me.