1

此 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;
}
}
?>
4

1 回答 1

1

如果你在 windows 界面中编写 php,那么我认为你不需要 chmod,chmod 仅适用于 Linux 基础。同时帮助自己解决这个问题

于 2012-08-14T20:47:47.310 回答