这个PHP脚本上传了一个图像文件,当图像上传到可在浏览器中查看的目录时,但是当我在Windows资源管理器中导航到图像时,我无法查看它。造成这种情况的原因是什么?为什么图像会以这种方式表现?
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name)) {
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats)) {
if($size<(1024*1024)) {
$actual_image_name = time().".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
//This is where the image upload is executed.
if(move_uploaded_file($tmp, $path.$actual_image_name)) {
chmod($path.$actual_image_name, 0777);
echo "<img src='".$path.$actual_image_name."' class='preview' width='306px'>";
}
else {
echo "failed";
}
}
else {
echo "Image file size max 1 MB";
}
}
else {
echo "Invalid file format..";
}
}
else {
echo "Please select image..!";
exit;
}
}
?>