什么会导致在浏览器中通过PHP显示上传的图像,而不是在Windows资源管理器中?

什么会导致在浏览器中通过PHP显示上传的图像,而不是在Windows资源管理器中?

问题描述:

This PHP script uploads a file which is an image, when the image has been uploaded to the directory it is viewable in the browser, but when I navigate to the image in Windows Explorer I can not view it. What would be the cause of this and why is image behaving in this manner?

$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;
}
}
?>

此PHP脚本上传文件即图像,当图像上传到目录中时可以查看 浏览器,但是当我在Windows资源管理器中导航到图像时,我无法查看它。 造成这种情况的原因是什么?为什么图像会以这种方式运行? p>

  $ valid_formats = array(“jpg”,“png”,“gif”,“  bmp“,”jpeg“); 
if(isset($ _ POST)和$ _SERVER ['REQUEST_METHOD'] ==”POST“){
 $ name = $ _FILES ['photoimg'] ['name']; \  n $ size = $ _FILES ['photoimg'] ['size']; 
if(strlen($ name)){
 list($ txt,$ ext)= explode(“。”,$ name); 
  if(in_array($ ext,$ valid_formats)){
 if($ size&lt;(1024 * 1024)){
 $ actual_image_name = time()。“。”。$ ext; 
 $ tmp = $ _FILES [  'photoimg'] ['tmp_name']; 
 //这是执行图像上传的地方。
如果(move_uploaded_file($ tmp,$ path。$ actual_image_name)){
 \ chmod($ path。$ actual_image_name,  0777); 
 echo“&lt; img src ='”。$ path。$ actual_image_name。“'class ='preview'width ='306px'&gt;”; 
} 
 else {
 echo“failed”  ; 
} 
} 
其他{
 echo“图像文件大小最大1 MB”; 
} 
} 
e  lse {
 echo“文件格式无效..”; 
} 
} 
else {
 echo“请选择图片..!”; 
退出; 
} 
} 
?
&gt; \  n  code>  pre> 
  div>

If you are writing php in windows interface then I don't think you need to chmod, chmod is only for Linux base. In the meantime help yourself with this.