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 : Handle multiple file upload
Categories : Complete Programs, Filesystem, PHP, HTML and PHP Update Picture
Ronny Haryanto
Date : Apr 16th 1999
Grade : 3 of 5 (graded 6 times)
Viewed : 27590
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  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
This simple PHP script encodes an HTML document so that its contents may be displayed as a web page.
Categories : Complete Programs, HTML and PHP, PHP
Complete NotePad application for Websites (Like Yahoo Notepad)
Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs
A simple php file uploader
Categories : PHP, Filesystem, 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
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
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
GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions
Contents Page - a script to build contents pages.
Categories : Complete Programs, PHP, Utilities, Filesystem
Open directory and File download
Categories : PHP, Filesystem, Directories, HTML and PHP
This script allows people to add their favorite quotes to your website. This could easily be modified to be a guestbook script or comment page script.
Categories : PHP, Complete Programs, HTML and PHP, Misc
PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use!
Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP
phpEasyMail: An easy way to send data from HTML-forms via EMail.
Categories : Email, HTML and PHP, Complete Programs, PHP
Validator 98 - a PHP-script to generate form-validation-code in JavaScript.
Categories : Complete Programs, Java Script, PHP, HTML and PHP
Finds files on your site, uses UNIX find command.
Categories : Complete Programs, Filesystem, PHP
 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)...