Useful multiple file upload PHP script.
I have created this script, that allows users to upload multiple files in PHP (find it attached at the end of this article). It is great for anyone that needs to add any sort of upload functionality, and would be a good base to make an upload service with.
Some features:
- Dynamic amount of uploads.
- Limit to only certain file types.
- Size limit on uploads.
- Avoids over writing due to duplicate file names.
You can edit the amount of uploads in the $numuploads variable, with simple edit you can allow users to select how many files they would like to upload. You can set the maximum upload size in the ‘maxsize’ hidden input. At default this script is set to only allow for Microsoft Word .doc files, but can bet set to anything in the $filetype == “…” IF statement, for example if you want to only allow MP3s set the filetype to audio/mpeg.
Hope this helps you, leave a comment if you have any questions.
Posted in PHP Code

March 11th, 2008 at 10:30 am
hi jason,
sorry if this sounds lame, but where do you specify the directory and the domain name where the files should be uploaded to?
March 11th, 2008 at 10:58 am
Have a look at the $target variable
March 23rd, 2008 at 4:26 pm
Is it possible to email the files or email someone of a new upload?
March 25th, 2008 at 9:52 am
@kazz have a look at using phpmailer. It’s simple to implement.
http://www.theopensurgery.com/15/using-the-phpmailer-library-to-send-html-emails-using-an-smtp-server/
April 9th, 2008 at 6:58 pm
Hi great script thanks!
say if I want to only accept a ceratin file type, for example *.tos, how would I do that?
April 10th, 2008 at 2:53 pm
sorry just found out you wrote it above
April 16th, 2008 at 2:33 pm
Script look great, but is it possible to allow every file type to be uploaded?
May 14th, 2008 at 7:22 am
@ Stadford
Just look at line 15 and make it the following:
if ($filetype != ” “)
That should do it quick and dirty :o)
Chris
June 16th, 2008 at 3:56 pm
I don’t know what a .rar filetype is. How am I supposed to run it? Sorry but I’m new to this. thanks.
June 19th, 2008 at 7:52 am
hi, thanks for the script
i have 2 question.
what if i want to allow upload of jpg, gif and png files? (3 file types)
where do i set the upload dir?
hope you can help, thnaks.
June 19th, 2008 at 6:15 pm
hi,
thanks for the script.
is it possible for me to enable multiple file extensions? eg, jpg, gif and png?
thanks
July 1st, 2008 at 5:04 pm
Yes of course, that is not so hard
Look at if($filetype = “application/msword”)
For example you can do:
if($filetype = “image/jpeg” or $filetype = “image/png” or $filetype = “image/gif”){
This will check for jpeg or png OR gif. Quite easy not?
July 10th, 2008 at 5:52 pm
An easy way to set allowed file extensions is if ($string1 == “jpg” || $string1 == “JPG” || $string1 == “jpeg” || $string1 == “JPEG”||…………..) etc …….’do this’….
Always advisable to check the filetype properly, not just using the extension…
use…
if ($_FILES["xxxxxxx"]["type"][0] == “image/jpeg”)…….’do this’………
August 6th, 2008 at 1:36 pm
Hi:
Excellent script. Love it! Quick question from a newbie. sorry.
How do I specify the exact location (directory and all) in $target. Can you please give an example? Many thanks!
October 21st, 2008 at 9:17 pm
Nice script! Thanks!
November 8th, 2008 at 1:19 pm
Hi Jason, just found this script which looks exactly what I’m looking for. what do I need to make sure that its secure and not open to abuse? Cheers, D.
December 28th, 2008 at 1:14 am
If you add a “Rating” system to this then I believe you would be the only one! I have searched hi and low for an MP3 upload that allows members to rate or vote for on MP3 and I cannot find one. It would need to have protection from more than 1 vote from the same IP.
March 2nd, 2009 at 1:26 am
Hello, would anyone know how to add video files such as, FLV, Mpeg, or WMV to be the files you want to upload? does not seem to work you put, video/flv or flash/flv?
March 2nd, 2009 at 4:29 pm
Hello, would anyone know how to add video files to upload, like, flv, wmv or mpeg? all my efforts have failed, alls i keep getting is the improper file error?
April 10th, 2009 at 10:52 am
HI,
I’m developing a site that allows for multiple jpg upload but after they are uploaded, i need the script to do some processing like file rename, and then make an entry in the database for each file.
Any suggestions??
Cheers!
April 18th, 2009 at 11:16 pm
Nice script, but how can I put the form on some page of Wordpress Blog? Forgive me I don“t understand php :,,(
April 21st, 2009 at 4:46 pm
What would be really cool if after the upload it provided a list of the newly created URLs for the uploaded files, maybe someone who knows what they are doing can hook it up?