Multiple file uploads |
[eluser]neen[/eluser]
Hi there, I have a form like so: Code: <form action="upload" enctype="multipart/form-data" method="post"> How can I use the upload library with the above form? I get an error when I try to upload (You did not select a file to Upload.)
[eluser]Colin Williams[/eluser]
You either need to give each file input a unique name (featured_image_0, featured_image_1) etc, and process each one in a loop, or overload the Uploader class to handle file upload arrays. Copying this from an earlier post I made: So, yeah, I was failing to pass $config from my constructor to CI_Upload's constructor... I also updated it so the API remains the same, just call $this->upload->do_upload(), not ->do_multi_upload() Code: <?php A few caveats that should be addressed: The $this->upload->data() method will only return data of the last file to be uploaded, not all files uploaded. If one of the fields errors, there is no way to know which individual one was erroneous. Not impossible problems to solve, but the code above has yet to address either of them. I'll work on rounding it out if I get some time, or need to do it myself. For now, it might be good to just have unique names for x number of upload fields, then process each one individually. Here's my controller: Code: <?php And my view: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
[eluser]neen[/eluser]
I never thought about that, but now I am doing using a completely separate field for each file...it is working perfectly! Here's my code: Code: public function upload() Obviously I am going to need to edit the $config stuff (gonna chuck that in config/upload.php)
[eluser]neen[/eluser]
I forgot to mention, but there are some custom things in there.. This is basically a system to let my users select a 'series' to show on the front page of my website. I am renaming the image file for normalization reasons (I never need to store that info in the database, since the system will know exactly what the image name is based on the category).
[eluser]Colin Williams[/eluser]
That is definitely the route to go in order to work nicely with the standard Upload class.
[eluser]drewbee[/eluser]
I see that you are on the right track, and one thing I would like to point out is that when naming your files, dont give them a position in the array. IE Code: <form action="upload" enctype="multipart/form-data" method="post"> Just personal preference I guess, but I have always seen it done this way.
[eluser]neen[/eluser]
Actually, if I use an array, it makes it hell to use the standard upload class (because it is not expecting a multi-dimensional array for the fields)...so instead, I am using _1, _2, _3, etc
[eluser]frietkot[/eluser]
I'm using the code from Colin Williams and it works great. But how do I incorporate the image_lib class to upload multiple images and then resize them?
[eluser]amites[/eluser]
Another option is to use the library I published at http://www.mitesdesign.com/blog/open-sou...de-igniter uses a JQuery dialog to upload multiple files from a single input, though the process beyond that is much the same as what's been posted, though I don't know if they've tested their code yet, gotta love the community here
[eluser]Colin Williams[/eluser]
My offering is more of the start of a solution, not a complete one. Seems better to just name your fields uniquely and upload them in a loop. |
Welcome Guest, Not a member yet? Register Sign In |