WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
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
Submit Site
Forex Trading Online forex trading platform

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 : Handle multiple file upload
Categories : Complete Programs, Filesystem, PHP, HTML and PHP Update Picture
Ronny Haryanto
Date : Apr 16th 1999
Grade : 2 of 5 (graded 2 times)
Viewed : 19364
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ronny Haryanto
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
/* Handle multiple file upload easily */
/* by Ronny Haryanto <giant@canada.com> */
/* February-ish 1999 */

/* Use it however you want. I'm not responsible for what you do with it. */

/* how many upload slots? */
define("UPLOAD_SLOTS", 5);

/* where to move the uploaded file(s) to? */
define("INCOMING", "/home/ronny/incoming/");

if($REQUEST_METHOD!="POST")
{
        /* generate form */
        echo "<form enctype=\"multipart/form-data\" method=post>\n";
        for($i=1; $i<=UPLOAD_SLOTS; $i++)
        {
                echo "<input type=file name=infile$i><br>\n";
        }
        echo "<input type=submit value=upload></form>\n";
}
else
{
        /* handle uploads */
        $noinput = true;
        for($i=1; $noinput && ($i<=UPLOAD_SLOTS); $i++)
        {
                if(${"infile".$i}!="none") $noinput=false;
        }
        if($noinput)
        {
                echo "error uploading. create 150MB coredump instead?";
                exit();
        }
        for($i=1; $i<=UPLOAD_SLOTS; $i++)
        {
                if(${"infile".$i}!="none" &&
                 copy(${"infile".$i}, INCOMING.${"infile".$i."_name"}) &&
                 unlink(${"infile".$i}))
                {
                        echo ${"infile".$i."_name"}." uploaded<br>";
                }
        }
} /* else */
?>



Directory viewer, customize how you display the file structure, easy to understand. Found out about PHP 3 days ago, and this is my first prog.
Categories : HTML and PHP, Complete Programs, Directories, Filesystem, PHP
phpCards - PHP/mySQL postcard script with web based admin to add, edit, and delete cards and categories. Very easy to install.
Categories : PHP, Complete Programs, HTML and PHP, MySQL
phpWebCam v1.0- Webcam management software - Automatically checks if you're online, and comes with a caption tool capable of handling multiple users.
Categories : PHP, Complete Programs, HTML and PHP
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
File Explorer, browse, upload, download and edit your web site files with only a browser and a HTTP connection.
Categories : Complete Programs, Content Management, Filesystem, PHP
GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions
This is a redirection program which is as good as the come.to v3 url redirection, complete with admin interface all clients stored in mysql
Categories : PHP, MySQL, Ecommerce, HTML and PHP, Complete Programs
PHP mySQL learning example This is a complete program to modify tables in a mySQL database on a nice and neat way.
Categories : PHP, MySQL, Complete Programs, HTML and PHP
Finds files on your site, uses UNIX find command.
Categories : Complete Programs, Filesystem, PHP
AITSH Statistics
Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP
This is a simple photo gallery that reads the image files from multiple directories, and generates a web page styled with CSS1. It opens single auto window to view and print a given image.
Categories : Graphics, Filesystem, PHP, Complete Programs
Disk Usage, uses UNIX du command.
Categories : Complete Programs, PHP, Filesystem
phpAddQuote v1.2 - UPDATED! Lets users add their own quotes to your website. You specify how many quotes appear on the page at a time. Easier install!
Categories : HTML and PHP, Complete Programs, PHP, Databases, Personalization and Membership
QTO File Manager
Categories : Filesystem, filePro, Complete Programs, PHP, Content Management
How to let a user download a picture by clicking on it instead of needing to right click and Save-As.
Categories : HTTP, PHP, HTML and PHP, Filesystem
 Mike Cacc wrote : 129
This is a great script.  There is one thing that can make 
it perfect...
A loading meter - showing the user the status of their 
uploads.  People hate waiting unsure of if their upload 
is actually working.  Anyone think they can add this???
 
 Ronny Haryanto wrote : 130
&gt;This is a great script.

Thank you. I`m glad that it can be useful.

&gt;There is one thing that can make
&gt;it perfect... 
&gt;A loading meter - showing the user the status of their
&gt;uploads. People hate waiting unsure of if their upload
&gt;is actually working. Anyone think they can add this???

I don`t think the protocol itself (HTTP) makes it possible.
I guess this is up to the browser, since the browser is the
one
doing the sending.
 
 Wang DaQing wrote : 183
I have changed the copy file part from:
    for($i=1; $i&lt;=UPLOAD_SLOTS; $i++) 
    { 
        if(${"infile".$i}!="none" && 
         copy(${"infile".$i}, 
INCOMING.${"infile".$i."_name"}) && 
         unlink(${"infile".$i})) 
        { 
            echo ${"infile".$i."_name"}." uploaded&lt;br&gt;"; 
        } 
    } 
to use move method. I think it will get better 
performance.
But I don`t know will it work ok on all platform.
    for($i=1; $i&lt;=UPLOAD_SLOTS; $i++) 
    { 
        if(${"infile".$i}!="none") { 
        $dstname = 
INCOMING.${"infile".$i."_name"};
        if(file_exists($dstname))
        unlink($dstname);
            if( rename(${"infile".$i},$dstname) )
            echo ${"infile".$i."_name"}." 
uploaded&lt;br&gt;"; 
        } 
    } 
 
 Fabrice Durieu wrote : 234
Very usefull script !!!
But there is a pb for big files ... the brownser stop 
sending the file.
 
 WorldMaker wrote : 274
A friend wishes for it to ask before overwriting a file...  If 
you could, could you e-mail me code to get us started...  
If not, I understand....
 
 Ronny Haryanto wrote : 448
Note that multiple file upload support has been included
in PHP since version 3.0.10 (check the manual). So this script
is possibly not needed if you use that version or greater.
 
 Michael Croft wrote : 475
does this work on win2000 server with php4? I`d try  it but I`m too lazy right now...probably will later
 
 JD Daniels wrote : 541
RE: Durieu Fabrice Question,

The Problem is not with any code, It is with PHP configuration.... Open the php.ini and change
upload_max_filesize = 2M to however large of files you need. PHP defaults to only 2mb. (remember to restart apache after you are done)
 If you don`t have access to php.ini, put a .htaccess file in your scripts directory with this line:
php max_upload_size = 10mb (or whatever you need)
Note:- I may have the syntax for the .htaccess a little screwed.. I haven`t actually had to use it yet :)
 
 mike wrote : 652
Anyone knows what should I do so this script will upload only jpg and gif files?????
Thanks.
Mike
 
 Hannu Kikkas wrote :705
Answer to problem/comment given (wayyy) before...

Adding a big file can be difficult because the MAX_FILE_SIZE in php.ini might be smaller than the file ready to be uploaded (default is 2M)...