2012-04-14 83 views
2

我刚刚工作,然后我认为我完成了,它停止工作。如果该文件不是图像,我试图让它发出错误。这里是我谈论的那部分。任何帮助将很乐意欣赏刚刚完成一个图像上传php mysql

$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 
+0

您的压痕是可怕的阅读。所以有什么问题?我不相信这是在那个代码段。 – j13r 2012-04-14 20:17:13

+0

为什么有一组错误,然后在将一个值放入之后退出?另外,你的'$ show'变量是多余的 - 使用'if(count($ errors)){// Show Errors Here}'(或者如果你没有初始化它'if(isset($ errors)){。 ..}') – Basic 2012-04-14 20:23:26

+0

它是如何“停止工作”?它允许各种文件吗? – 2012-04-14 20:24:14

回答

1

这是错误

A. $_FILES ['images'] ['size'] [$i]如果你期待多图片上传只会工作

解决方案

你应该只使用$_FILES ['images'] ['size']

B.后续的脚本是错误的

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

只需使用

if($_FILES['images']['error'] == 0){ 

如果你正在处理多个图像..已经给很多例子这里之前看到的。

limiting the checking condition while uploading swf files

PHP - Saving Uploaded Image to Server

1

你不应该使用“退出;”。它会结束所有的PHP执行,并且你的代码将无法运行。

+0

把它们拿出来,仍然没有去 – Keezy 2012-04-14 20:55:12