Useful multiple file upload PHP script.
March 5th, 2008 by jason
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’………