Upload unlimited files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Upload unlimited files

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Upload unlimited files

Post by AbraCadaver »

If you use Javascript you can add a new file input after they select a file in the first one, etc...
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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!
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Upload unlimited files

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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
mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Upload unlimited files

Post by Jonah Bron »

mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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.
mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Upload unlimited files

Post 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.
mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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
mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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. :drunk:

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.
kgrote
Forum Newbie
Posts: 3
Joined: Wed May 12, 2010 10:20 am

Re: Upload unlimited files

Post 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!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Upload unlimited files

Post by Jonah Bron »

Great! Looks like you're leaning fast.

:)
mickyjune26
Forum Commoner
Posts: 30
Joined: Mon May 17, 2010 9:52 am

Re: Upload unlimited files

Post 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.
Post Reply