【问题标题】:just got done with an image upload php mysql刚刚完成图片上传 php mysql
【发布时间】: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


【解决方案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

【讨论】:

    【解决方案2】:

    你不应该使用“exit;”。它会结束所有 PHP 执行,之后您的代码将无法运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      相关资源
      最近更新 更多