This little script works in every browser(tested in FF,Opera,Safari) except Internet Explorer. I'm stumped as to why the image is failing on the copy from temp to "upload/" folder. Folder has 777 permissions and is chown'd correctly. Is there anything about IE that could cause this to fail only in IE? In IE it's failing on this line:
Code: Select all
if(move_uploaded_file($tmp_name, $target_path)) {Code: Select all
session_start();
if (isset($_GET['grd'])) {
if (isset($_POST['submit'])) {
switch ($_GET['grd']) {
case "upload":
if (($_POST['cust_name'] == "") && (strlen($_POST['cust_name']) < 2)) {
$_SESSION['status_msg'] = "Please fill in name(at least 2 characters)";
break;
}
$image_types = array('image/bmp','image/jpeg','image/jpg','image/png','image/gif');
$random_digit = rand(100000,999999);
foreach ($_FILES["uploadedfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$target_path = "upload/$random_digit"."_{$_POST['cust_name']}_".basename($_FILES['uploadedfile']['name'][$key]); #folder needs to be chmoded to 777!!!
if ($_FILES['uploadedfile']['size'][$key] > 5120000) {
$_SESSION['status_msg'] = "The file".$_FILES['uploadedfile']['name'][$key]." is too large. ";
break 1;
}
$tmp_name = $_FILES["uploadedfile"]["tmp_name"][$key];
if(!in_array(strtolower($_FILES["uploadedfile"]["type"][$key]), $image_types)) {
$_SESSION['status_msg'] .= $_FILES['uploadedfile']['name'][$key]." unknown file type...upload unsuccessful!<br />";
break 1;
}
if(move_uploaded_file($tmp_name, $target_path)) {
$_SESSION['status_msg'] .= $_FILES['uploadedfile']['name'][$key]." <span style=\"color: green\">successfull!</span><br />";
} else {
$_SESSION['status_msg'] .= $_FILES['uploadedfile']['name'][$key]." <span style=\"color: red\">upload unsuccessfull!</span><br />";
}
}
} # end foreach
default:
break;
} # end switch
} # end post submit
} # end get actionCode: Select all
<body>
<?
if (isset($_SESSION['status_msg'])) {
echo("<span style=\"color: red\">".$_SESSION['status_msg']."</span><br>");
unset($_SESSION['status_msg']);
}
?>
* = required<br /><br />
<form name="a" enctype="multipart/form-data" action="?grd=upload" method="post">
Name *<input type="text" name="cust_name" value="<?=$_POST['cust_name']?>" /><br /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
Choose file(s) to upload:<br />
<input name="uploadedfile[]" type="file" size="70" /> max file size: 5 meg<br />
<input name="uploadedfile[]" type="file" size="70" /><br />
<input name="uploadedfile[]" type="file" size="70" /><br />
<input name="uploadedfile[]" type="file" size="70" /><br />
<input type="submit" name="submit" value="Upload File" />
</form>
</body>