当我上传图片时,我可以在浏览器中查看它,但是当我尝试从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'];
if(move_uploaded_file($tmp, $path.$actual_image_name)) {
echo "<img src='uploads/".$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;
}
}
?>
答案 0 :(得分:1)
你可以试试这个:
if(move_uploaded_file($tmp, $path.$actual_image_name)) {
chmod($path.$actual_image_name, 0666); # set file to read-write for everybody
echo "<img src='uploads/".$actual_image_name."' class='preview' width='306px'>";
}