Forum Moderators: coopster

Message Too Old, No Replies

Codes for uploading an image to a directory using PHP

         

irock

2:05 am on Feb 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, I'm having difficulties trying to upload an image to a directory using some PHP codes. Some of the scripts I found are over kill. I only need something that works by allowing users to select multiple files from their desktops and to upload to the pre-defined directory. Are there any simple samples out there?

Thanks!

crypto

5:39 am on Feb 15, 2003 (gmt 0)

10+ Year Member



Irock,

You can try this out:

<form name="upload_form" method="post" action="upload.php" enctype="multipart/form-data">
Picture 1 : <input type="file" name="userfile[]">
Picture 2 : <input type="file" name="userfile[]">
Picture 3 : <input type="file" name="userfile[]">
Picture 4 : <input type="file" name="userfile[]">
</form>

Now in upload.php you can have:
-------------------------------

<?
global $userfile,$userfile_name,$userfile_size;

$max=4; //No. of uploaded images
$dir="/images"; //Your upload directory

for ($i=0;$i<$max;$i++)
{
if ($userfile_size[$i] > 0)
{
$filename[$i] = basename($userfile_name[$i]);
$target="$dir/".$filename[$i];
if(!@copy($userfile[$i],$target)) die("Error: A problem occured while uploading $filename[$i]. Aborting...");
}
}
?>