Does anyone know How I can get each image name so that I can insert each name into its own database field ?
Also I am trying to figure out how to echo an image name that does not get uploaded based on wrong ext and size...
I been at this all day so if you can help me out, that would be great.
<?
if($submit == "Send"){
$uploaddir = "upload";
//files to upload to
$allowed = array("image/jpeg", "image/pjpeg", "image/jpg", "image/gif");
//images allowed
$max_size = "50000"; // about 50kb
//max size of file
$unique_id = md5(uniqid(time()));
//give image name a id
foreach ($_FILES["files"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["files"]["tmp_name"][$key];
$name = $_FILES["files"]["name"][$key];
$filename = $unique_id.'_'.$_FILES["files"]["name"][$key];
$fame = move_uploaded_file($tmp_name, "$uploaddir/$filename");
if(in_array($_FILES['files']['type'][$key], $allowed))
{
$okk = "1";
} else {
$hmm="Wrong image type</b>";
}
if($_FILES['files']['size'][$key] < $max_size)
{
$ok = "2";
} else {
$hmm="Wrong image size<BR><b>Image must not be larger then $max_size k";
}
if (($ok == "2") && ($okk == "1")){
move_uploaded_file($tmp_name, "$uploaddir/$filename");
echo "Success Image Upload";
} else {
echo "$hmm";
}
}
}
}
?>
<html>
<head>
<title>test page</title>
</head>
<body>
<form action="upload_test2.php" method="post" enctype="multipart/form-data">
<p>Files: <BR>
<input type="file" name="files[]" /><BR>
<input type="file" name="files[]" /><BR>
<input type="file" name="files[]" /><BR>
<input type="file" name="files[]" /><BR>
<input type="file" name="files[]" /><BR>
<input type="file" name="files[]" /><BR>
<!-- You can add more fields by using the same syntax above. -->
<input type="submit" name="submit" value="Send" />
</p>
</form>
</body>
</html>