Hi,
Can someone tell me how to edit this code to allow multiple image uploads..it works great with one but I dont know how to add more.
Thanks!
~D
<?
// CONFIG
$serverpath = "upload/"; // Path to where images should be uplothe server.
$urltoimages = "http://whateverserver.com/catalog/upload/"; // Web address to where the images are accessible from.
$maxsize = "10000000"; // Example - 20000 is the same as 20kb
$uniq = uniqid("");
// CONFIG END
// CONFIG END
$mode = $_GET['mode'];
if ($mode == "") { $mode = "form"; }
if ($mode == "form") {
echo "<form enctype='multipart/form-data' method='post' action='index.php?mode=upload'>\n";
echo "<input type='file' name='file'><BR>\n";
echo "<input type='submit' name='Submit' value='Upload'>\n";
}
if ($mode == "upload") {
$file = $_FILES['file']['name'];
// If you add your own file types don't forget to add an uppercase version.
$allowedfiles[] = "gif";
$allowedfiles[] = "jpg";
$allowedfiles[] = "jpeg";
$allowedfiles[] = "png";
$allowedfiles[] = "GIF";
$allowedfiles[] = "JPG";
$allowedfiles[] = "JPEG";
$allowedfiles[] = "PNG";
if($_FILES['file']['size'] > $maxsize)
{
print "File size is too big - please reduce file size and try again.";
}
else {
$path = "$serverpath/$file";
foreach($allowedfiles as $allowedfile) {
if ($done <> "yes") {
if (file_exists($path)) {
echo "A file with this name already exists - please rename the file and reupload.";
exit;
}
}
if (substr($file, -3) == $allowedfile) {
move_uploaded_file($_FILES['file']['tmp_name'], "$path");
$done = "yes";
echo "<p><img src='$urltoimages/$file' border='0'>";
echo "<p><strong>$file</strong></p>";
}
}
if ($done <> "yes") { print "<p><b>Error:</b> Your image as not been uploaded becuase it is not a recognised image file. Please try again.</p>"; }
}
}
?>