WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Upload Multiple Files multi-uploader (Easy Code)
Categories : PHP, Filesystem Click here to Update Your Picture
Mohammed Ahmed
Date : Aug 31st 2005
Grade : 3 of 5 (graded 7 times)
Viewed : 13586
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Mohammed Ahmed
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

By using this script you will be able to upload as many files as you want.
The code will check if file existes, limited extensions, file size, file selected ..etc.
For Q. E-mail/MSN: m(at)maaking.com.

<?php
###########################################
#----------Upload Multiple Files----------#
#----------Multi-files Uploader-----------#
#-------------Multi-Uploader -------------#
###########################################
/*=========================================\
Author      :  Mohammed Ahmed(M@@king)    \\
Version     :  1.0                        \\
Date Created:  Aug 20  2005               \\
----------------------------              \\
Last Update:   Aug 31 2005                \\
----------------------------              \\
Country    :   Palestine                  \\
City       :   Gaza                       \\
E-mail     :   m@maaking.com              \\
MSN        :   m@maaking.com              \\
AOL-IM     :   maa2pal                    \\
WWW        :   http://www.maaking.com     \\
Mobile/SMS :   00972-599-622235           \\
                                          \\
===========================================\
------------------------------------------*/
//upload directory.
//change to fit your need eg. files, upload .... etc.
$upload_dir = "images/";
//number of files to upload.
$num_files = 5;
//the file size in bytes.
$size_bytes =51200; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png",".txt",".nfo",".doc",".rtf",".htm",".dmg",".zip",".rar",".gz",".exe");


   
//check if the directory exists or not.
   
if (!is_dir("$upload_dir")) {
      die (
"Error: The directory <b>($upload_dir)</b> doesn't exist");
   }
   
//check if the directory is writable.
   
if (!is_writeable("$upload_dir")){
      die (
"Error: The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)");
   }


//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

       echo
"<h3>Upload results:</h3>";

       
//do a loop for uploading files based on ($num_files) number of files.
       
for ($i = 1; $i <= $num_files; $i++) {

           
//define variables to hold the values.
           
$new_file = $_FILES['file'.$i];
           
$file_name = $new_file['name'];
           
//to remove spaces from file name we have to replace it with "_".
           
$file_name = str_replace(' ', '_', $file_name);
           
$file_tmp = $new_file['tmp_name'];
           
$file_size = $new_file['size'];

           
#-----------------------------------------------------------#
           # this code will check if the files was selected or not.    #
           #-----------------------------------------------------------#

           
if (!is_uploaded_file($file_tmp)) {
             
//print error message and file number.
             
echo "File $i: Not selected.<br>";
           }else{
                 
#-----------------------------------------------------------#
                 # this code will check file extension                       #
                 #-----------------------------------------------------------#

                 
$ext = strrchr($file_name,'.');
                 if (!
in_array(strtolower($ext),$limitedext)) {
                    echo
"File $i: ($file_name) Wrong file extension. <br>";
                 }else{
                       
#-----------------------------------------------------------#
                       # this code will check file size is correct                 #
                       #-----------------------------------------------------------#

                       
if ($file_size > $size_bytes){
                           echo
"File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";
                       }else{
                             
#-----------------------------------------------------------#
                             # this code check if file is Already EXISTS.                #
                             #-----------------------------------------------------------#

                             
if(file_exists($upload_dir.$file_name)){
                                 echo
"File $i: ($file_name) already exists.<br>";
                             }else{
                                   
#-----------------------------------------------------------#
                                   # this function will upload the files.  :) ;) cool          #
                                   #-----------------------------------------------------------#
                                   
if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
                                       echo
"File $i: ($file_name) Uploaded.<br>";
                                   }else{
                                        echo
"File $i: Faild to upload.<br>";
                                   }
#end of (move_uploaded_file).

                             
}#end of (file_exists).

                       
}#end of (file_size).

                 
}#end of (limitedext).

           
}#end of (!is_uploaded_file).

       
}#end of (for loop).
       # print back button.
       
echo "»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
////////////////////////////////////////////////////////////////////////////////
//else if the form didn't submitted then show it.
}else{
    echo
" <h3>Select files to upload!.</h3>
           Max file size = "
. $size_bytes / 1024 ." KB";
    echo
" <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
           
// show the file input field based on($num_files).
           
for ($i = 1; $i <= $num_files; $i++) {
               echo
"File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
           }
    echo
" <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
           <input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
           </form>"
;
}

//print copyright ;-)
echo"<p align=\"right\"><br>Script by: <a href=\"http://www.maaking.com\">maaking.com</a></p>";
?>



Convert a File database into MySQL
Categories : PHP, Filesystem, Databases, MySQL, Beginner Guides
Remote File Size
Categories : PHP, Filesystem, HTTP, Sockets
Quote For the Day
Categories : PHP, Utilities, Filesystem
How to ifconfig down/up a list of IP's
Categories : Arrays, Strings, Filesystem, PHP
Variable serialization and unserialization. Loading and saving variable structures to and from file.
Categories : Arrays, Filesystem, Variables, Strings, PHP
Finds files on your site, uses UNIX find command.
Categories : Complete Programs, Filesystem, PHP
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
Download manager - A PHP script for adding a download page to any site.It also enables you track the no. of downloads.
Categories : PHP, Content Management, Filesystem, Databases, MySQL
Get the correct extension and MIME types of an image, even when the filename is incorrect.
Categories : PHP, Filesystem, General SQL
Selecting a random line from a text file
Categories : PHP, Filesystem, Arrays, Beginner Guides
Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML -
Categories : PHP, Directories, FTP, Filesystem, HTML and PHP
JSON File Upload
Categories : PHP, AJAX, Filesystem
include php3 files
Categories : Filesystem, PHP, Apache, Web Servers
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
Upload function using PHP's FTP abilities.
Categories : PHP, Filesystem, FTP