刚刚完成了一个图片上传php mysql

刚刚完成了一个图片上传php mysql,php,forms,file-upload,Php,Forms,File Upload,我只是让它工作,然后我认为我做了,它停止工作。如果文件不是一个图像,我试图让它消除一个错误。这就是我说的那篇文章。任何帮助都将不胜感激 $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 im

我只是让它工作,然后我认为我做了,它停止工作。如果文件不是一个图像,我试图让它消除一个错误。这就是我说的那篇文章。任何帮助都将不胜感激

$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
$type_array=array('image/jpeg','image/gif','image/png','image/x-png')//允许的图像类型
如果(isset($_文件['images'][$i])和$_文件['images']['name'][$i]!=''){//检查图像
如果($_FILES['images']['size'][$i]<10240000){//请确保文件大于10mb
$type=$\u文件['images']['type'][$i];//获取文件类型
如果(!in_array($type,$type_array)){//请确保允许使用图像
$errors[]=“请检查您是否正在上载图像。”;
$show_errors='show';
出口
}
}否则{
$errors[]=“请确保每个文件小于10MB。”;
$show_errors='show';
出口
}
}//已检查图像
您不应该使用“退出;”。它将结束所有PHP执行,之后的代码将无法运行。

这是错误

A.
$\u文件['images']['size'][$i]
仅在需要多个图像上载时才起作用

解决方案

您应该只使用
$\u文件['images']['size']

下面的脚本是错误的

 if (isset ( $_FILES ['images'] [$i] ) and $_FILES ['images'] ['name'] [$i] != '') { // check
只用

  if($_FILES['images']['error'] == 0){ 
如果您正在处理多个图像。。在看到之前,这里已经给出了许多例子


你的缩进读起来很糟糕。那有什么问题?我不相信它在那个代码段中。为什么会有一个错误数组,然后在放入一个值后退出呢?另外,您的
$show
变量是冗余的-使用
if(count($errors)){//show errors Here}
(或者如果您没有初始化它,
if(isset($errors)){…}
)它是如何“停止工作的”?它允许所有类型的文件吗?它看起来应该可以工作…你可以看到这个上传图像的教程…@Basic在我的html代码中我有if(isset($error)),它显示数组中的任何错误。