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 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?