This is for 3 images to be uploaded
PHP Code:
//increase the number of files uploaded
$anythingyouwant = 'Put something here that randomizes incase 2 images with the same file name are put in or down below where the variable is referenced also it should increase at the start of this function';
$success = 0;
$fail = 0;
$uploaddir = 'uploads/';
for ($i=0;$i<3;$i++)
{
if($_FILES['userfile']['name'][$i])
{
$uploadfile = $anythingyouwant. basename($_FILES['userfile']['name'][$i]);
$ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
if (preg_match("/(jpg|gif|png|bmp)/",$ext))
{
if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile))
{
$success++;
}
else
{
echo "Error Uploading the file. Retry after sometime.\n";
$fail++;
}
}
else
{
$fail++;
}
}
}
echo '<div style="margin-top:210px" text-align:center;>';
echo "<br /> Number of files Uploaded:".$success;
echo "<br /> Number of files Failed:".$fail;
echo '</div>';
}
?>
This is the html i use
Code:
<form enctype="multipart/form-data" action="nameofthephpfileabove.php" method="post">
Image1: <input name="userfile[]" type="file" /><br />
Image2: <input name="userfile[]" type="file" /><br />
Image3: <input name="userfile[]" type="file" />
<input type="submit" value="Upload" />
</form>
Bookmarks