[英]PHP upload issue with code
我不断收到无效文件错误。 任何人都可以看到此脚本出了什么问题。 我是从W3学校获得的,文件夹“ pics / 2012 / Blackhall Primary /”确实存在
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("pics/2012/Blackhall Primary/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"pics/2012/Blackhall Primary/" . $_FILES["file"]["name"]);
echo "Stored in: " . "pics/2012/Blackhall Primary/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
包括更多这样的错误检查:
<?php
echo process_files();
function process_files()
{
$allowed_file_types=array('image/gif','image/jpeg','image/png','image/jpg','image/pjpeg');
if(0==sizeof($_FILES)) return 'no files uploaded';
if(!stristr($_FILES['file']['type'], 'image')) return 'file is not an image';
if(!in_array($_FILES['file']['type'], $allowed_file_types)) return 'image type '.$_FILES['file']['type'].' is not allowed';
if($_FILES['file']['size'] < 20000) return 'file size too large. Max:20000, File:'.$_FILES['file']['size'];
// rest of your code here!
}
?>
检查图片的扩展名,也许是大写的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.