Multiple File Upload |
[eluser]ShoeLace1291[/eluser]
I have a form where a user can upload photos to their gallery. I want them to be able to upload more than one photo at a time. So in my upload form, I have a file input called "files[]" along with a javascript code that let's them add more file fields with the same name. The PHP script that I have made goes through several steps. First, it goes through the process of the actual file upload. If the file upload is a success, it then creates an attachment file(as a database record) and then it creates the photo record in the database. When I return the upload data array, none of the array keys have any values. The display_errors function doesn't return any errors, either. Any ideas? Code: $this->load->library('form_validation');
[eluser]toopay[/eluser]
You can do this way. In your view : Code: <?php echo form_label('Image: ','userfile1');?> Then in your controller, something like these... Code: //Set File Settings
[eluser]ShoeLace1291[/eluser]
That's not how I'm doing it. The number of files being uploaded will be a random number chosen by the user and will be stored in an array called "file[]".
[eluser]toopay[/eluser]
[quote author="ShoeLace1291" date="1311773195"]That's not how I'm doing it. The number of files being uploaded will be a random number chosen by the user and will be stored in an array called "file[]".[/quote] What is the different? Above example just showing you the basic of how to handle multiple $_FILES. It still use some array pattern after all. You could just change userfile1, userfile2 with file[], indeed. Just iterate each field(s) with above mechanism/procedure.
[eluser]ShoeLace1291[/eluser]
Because in order to iterate through the inputs I need to know how many inputs there are. That's why I'm using the array because i can just use count($this->input->post('file')) so I can use a for statement.
[eluser]LuckyFella73[/eluser]
The problem with your script is that the files selected to upload are not contained in the POST array! Code: // won't work with files! You have to count the $_FILES array and loop through that - like toopay said.
[eluser]Flemming[/eluser]
For a multiple image upload feature with style and progress bar I've used plupload (http://www.plupload.com) and plugged it in to codeigniters upload class seamlessly. You might want to try that if you have a bit of time to spare to integrate it. |
Welcome Guest, Not a member yet? Register Sign In |