donglu6805 2012-08-14 20:33
浏览 6
已采纳

什么会导致在浏览器中通过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;
}
}
?>
  • 写回答

1条回答 默认 最新

  • doushi4956 2012-08-14 20:47
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata