【发布时间】:2012-04-14 20:13:49
【问题描述】:
我只是让它工作,然后我认为我已经完成并且它停止工作了。如果文件不是图像,我正试图让它排除错误。这是我正在谈论的那篇文章。任何帮助将不胜感激
$type_array = array('image/jpeg', 'image/gif', 'image/png','image/x-png'); //image types allowed
if(isset($_FILES['images'][$i]) and $_FILES['images']['name'][$i] != '') { //check image
if ($_FILES['images']['size'][$i] < 10240000) { //make sure file is larger than 10mb
$type = $_FILES['images']['type'][$i]; //get the file types
if (!in_array($type, $type_array)) { //make sure the images are allowed
$errors[] = "Please check that you are uploading an image.";
$show_errors = 'show';
exit;
}
} else {
$errors[] = "Please make sure each file is less than 10MB.";
$show_errors = 'show';
exit;
}
} //image checked
【问题讨论】:
-
你的缩进很难读。所以有什么问题?我不相信它在那个代码段中。
-
为什么会出现一系列错误,然后在其中输入一个值后退出?此外,你的
$show变量是多余的 - 使用if(count($errors)) {//Show Errors Here}(或者如果你不初始化它,if(isset($errors)){...}) -
它是如何“停止工作”的?它允许所有类型的文件吗?
-
它看起来应该可以工作......你可以看到这个上传图片的教程......reconn.us/content/view/30/51
-
@Basic 在我的 html 代码中我有 if(isset($error)) 显示数组中的任何错误。
标签: php forms file-upload