|
|
|
<?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 | | | 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 | | | Finds files on your site, uses UNIX find command. Categories : Complete Programs, Filesystem, PHP | |
| | Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML - Categories : PHP, Directories, FTP, Filesystem, HTML and PHP | | | Disk Usage, uses UNIX du command. Categories : Complete Programs, PHP, Filesystem | | | 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 | | | navbar.php3 - Dynamic hyperlinked navigation bars Categories : HTML and PHP, Arrays, PHP, Complete Programs | | | AITSH Statistics Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP | | | This program will take data from a user via a web based form, validate it, show it
to the user for re-validation, and finally insert it into the database. Plenty of
sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | Opening and formatting text files into HTML on the fly- or HTML from templates. Categories : PHP, HTML and PHP, Filesystem | | | 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 | | | 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 | | | DDN FFA Network Script Categories : PHP, MySQL, Complete Programs, HTML and PHP, Databases | |
| | | | 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
>This is a great script.
Thank you. I`m glad that it can be useful.
>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???
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<=UPLOAD_SLOTS; $i++)
{
if(${"infile".$i}!="none" &&
copy(${"infile".$i},
INCOMING.${"infile".$i."_name"}) &&
unlink(${"infile".$i}))
{
echo ${"infile".$i."_name"}." uploaded<br>";
}
}
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<=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<br>";
}
}
| | | | 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)...
| |
|
|