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.

Multi file upload script

del.icio.us Digg Technorati StumbleUpon

Posted in PHP Code

13 Comments

  1. rk

    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?

  2. jason

    Have a look at the $target variable ;)

  3. kazz

    Is it possible to email the files or email someone of a new upload?

  4. Steve

    Hi great script thanks!

    say if I want to only accept a ceratin file type, for example *.tos, how would I do that?

  5. Steve

    sorry just found out you wrote it above :)

  6. Stadford

    Script look great, but is it possible to allow every file type to be uploaded?

  7. Chris

    @ Stadford

    Just look at line 15 and make it the following:

    if ($filetype != ” “)

    That should do it quick and dirty :o)

    Chris

  8. Newbie

    I don’t know what a .rar filetype is. How am I supposed to run it? Sorry but I’m new to this. thanks.

  9. Leonard

    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.

  10. leo

    hi,

    thanks for the script.

    is it possible for me to enable multiple file extensions? eg, jpg, gif and png?

    thanks

  11. Reinder

    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? :)

  12. Pompey Photos

    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’………

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.