【问题标题】:How to see the error message in $_FILE array in PHP如何在 PHP 中查看 $_FILE 数组中的错误消息
【发布时间】:2013-12-30 07:24:05
【问题描述】:

我正在开发多个文件上传功能,当我将文件数组打印为时出现错误:

  print_r($_FILE);

得到错误:

Array
(
   [name] => _agiewniki_Forrest_in_Autumn.jpg
   [type] =>
   [tmp_name] =>
   [error] => 1
   [size] => 0
)

我没有看到错误描述,错误只有这个

[error] => 1

【问题讨论】:

    标签: php cakephp file-upload


    【解决方案1】:

    你可以使用这个数组来显示file-upload error messages:

    $error_messages = array(
        UPLOAD_ERR_OK         => 'There is no error, the file uploaded with success',
        UPLOAD_ERR_INI_SIZE   => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
        UPLOAD_ERR_FORM_SIZE  => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
        UPLOAD_ERR_PARTIAL    => 'The uploaded file was only partially uploaded',
        UPLOAD_ERR_NO_FILE    => 'No file was uploaded',
        UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder',
        UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk',
        UPLOAD_ERR_EXTENSION  => 'A PHP extension stopped the file upload',
    );
    
    // prints "The uploaded file exceeds the upload_max_filesize directive in php.ini"
    echo $error_messages[$_FILES['error']];
    

    【讨论】:

    • 感谢@Danijel 提供如此详细的答案
    【解决方案2】:

    http://www.php.net/manual/en/features.file-upload.errors.php

    UPLOAD_ERR_INI_SIZE 值:1;上传的文件超过了 php.ini 中的 upload_max_filesize 指令。

    希望能帮到你

    【讨论】:

      【解决方案3】:

      Here你可以通过错误代码找到描述

      在你的情况下是:The uploaded file exceeds the upload_max_filesize directive in php.ini.

      【讨论】:

        【解决方案4】:

        基于$_FILES['userfile']['error'] 值,您可以在参考文档中打印相应的错误消息。

        将某个数组中的所有错误消息与相应的错误键值相加。根据上传过程中从$_FILE收到的错误键值,并显示相应的错误消息[链接添加在下面]。

        错误信息解释:

        错误值:1;上传的文件超过了 php.ini 中的 upload_max_filesize 指令。

        更多信息请参考:http://www.php.net/manual/en/features.file-upload.errors.php

        【讨论】:

          猜你喜欢
          • 2020-04-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-08-18
          • 2012-07-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多