Page 1 of 2
Upload unlimited files
Posted: Thu May 20, 2010 3:15 pm
by mickyjune26
Using PHP, what is the best method to allow a user to upload files one at a time prior to completing a form?
Here is how I visualize:
1. User clicks Browse and selects file
2. User clicks upload and file uploads
3. Page shows newly uploaded file
4. User can click Browse to upload another file or Finish to submit the completed form
So far, i only know how to create more than one file input field ahead of time, limiting the user to upload 5 or less files at the same time, for example.
Thanks in advance.
Re: Upload unlimited files
Posted: Thu May 20, 2010 3:27 pm
by AbraCadaver
If you use Javascript you can add a new file input after they select a file in the first one, etc...
Re: Upload unlimited files
Posted: Thu May 20, 2010 3:42 pm
by mickyjune26
Yeah, I downloaded some scripts, but I don't know js yet. I'm just starting to understand the basics of PHP. If I have to learn js to do this, I will. But I'd like to stay in the realm of php.
Thanks for the quick response!
Re: Upload unlimited files
Posted: Thu May 20, 2010 4:03 pm
by AbraCadaver
Do it the way you have outlined. The process would be to make the form submit to itself and on submit it would store the uploaded file name in the session and display the upload form again with the already uploaded files. When they click finish, submit to another page.
Re: Upload unlimited files
Posted: Mon May 24, 2010 11:24 am
by mickyjune26
Per someone's suggestion, we are going a slightly different direction, incorporating some javascript to dynamically add more upload prompts.
http://www.htmlhelpcentral.com/messageb ... to=newpost
Re: Upload unlimited files
Posted: Mon May 24, 2010 2:46 pm
by mickyjune26
The current method of duplicating the browse button let's me select multiple files, but is only uploading one file. Anyone know how I can modify the php processing code so it can upload multiple files?
Form URL:
http://www.einstructiontx.com/tester_form.php
PHP processor:
http://www.einstructiontx.com/tester_upload.php
The submit button is disabled for now, until i add code to sanitize the uploads.
Re: Upload unlimited files
Posted: Mon May 24, 2010 4:30 pm
by Jonah Bron
Re: Upload unlimited files
Posted: Mon May 24, 2010 5:07 pm
by mickyjune26
Thanks Jonah. Once I finish my 10 remaining hours of php tutorials on lynda.com in addition to some tutorials that another devnetwork user recommended, I'll research the link you provided. It may be a while because it seems a little too advanced right now. I just built my first working form that updates a MySQL database
pretty cool stuff.
Re: Upload unlimited files
Posted: Mon May 24, 2010 5:47 pm
by mickyjune26
Jonah, I think I'm getting closer to understanding what you are meaning.
I found an explaination of how to upload multiple files.
http://www.phpeasystep.com/phptu/2.html
Once I play with and understand this code, I'll try incorporating the link you provided.
Re: Upload unlimited files
Posted: Mon May 24, 2010 5:51 pm
by John Cartwright
mickyjune26 wrote:Jonah, I think I'm getting closer to understanding what you are meaning.
I found an explaination of how to upload multiple files.
http://www.phpeasystep.com/phptu/2.html
Once I play with and understand this code, I'll try incorporating the link you provided.
That tutorial is really outdated, but covers the same principles as the previously posted tutorial.
Re: Upload unlimited files
Posted: Mon May 24, 2010 6:06 pm
by mickyjune26
awesome! I got the dynamic form to successfully upload multiple files to my processor. Now I just need to put some while and count loops in the processor so it can dynamically adjust. It's currently static and limited to 3.
http://www.einstructiontx.com/tester_form.php
http://www.einstructiontx.com/tester_processor.php
Re: Upload unlimited files
Posted: Mon May 24, 2010 6:26 pm
by mickyjune26
yeah, I noticed that the tutorial I found was outdated. It was nice how it went into more detail for a newbie like me.
My form and processor are fully functional now! I couldn't have done it without your guidance. I feel like celebrating, now that I've passed my 2nd full day of php coding.
Now I just need to find a way to duplicate the entire row in the form when Add More is clicked. I save that for a forum focusing on Javascript!
Thanks again everyone. I hope to be able to give back to this forum as much as has been given to me.
Re: Upload unlimited files
Posted: Mon May 24, 2010 6:53 pm
by kgrote
mickyjune26:
Would you be willing to post your code? I need to do the same thing and I'd love to see how it's done. Thanks!
Re: Upload unlimited files
Posted: Mon May 24, 2010 7:41 pm
by Jonah Bron
Great! Looks like you're leaning fast.

Re: Upload unlimited files
Posted: Mon May 24, 2010 7:50 pm
by mickyjune26
kgrote wrote:mickyjune26:
Would you be willing to post your code? I need to do the same thing and I'd love to see how it's done. Thanks!
Here you go:
http://www.einstructiontx.com/tester_form.php
http://www.einstructiontx.com/tester_processor.php
Next, I'll configure the files to go to a specific folder based on the drop-down attributes, such as Grade 3 > Science. Also need to add some security metrics.