【问题标题】:PHP Yii framework error message Undefined indexPHP Yii 框架错误信息 Undefined index
【发布时间】:2017-12-10 09:49:13
【问题描述】:

我正在尝试提供允许的扩展名,所以我确实尝试了这段代码,但我得到了错误提示

未定义索引:文件[]

  $ly_formname = 'files[]';

    $file_type = $_FILES[$ly_formname]['type']; //returns the mimetype

    $allowed = array("image/jpeg", "image/gif", "application/pdf");
    if(!in_array($file_type, $allowed)) {
      $error_message = 'Only jpg, gif, and pdf files are allowed.';
      $error = 'yes';
    }

我更改了我的变量名,但仍然收到消息错误

yii框架中的表单名是file[]

public function run()
    {
        return Html::input('file', 'files[]', null, $this->getOptions());
    }

我的输入代码是:

<input type="file" id="contentFormFilesGallery" name="files[]"
 multiple="multiple" title="Upload file" accept="image/*" data-upload-url="" 
data-upload-drop-zone="#contentFormBody" data-upload-
progress="#contentFormFiles_progress" data-upload-
preview="#contentFormFiles_preview" data-upload-form="" data-upload-single="" 
data-upload-submit-name="fileList[]" data-upload-hide-in-stream="" data-php-max-
file-uploads="20" data-php-max-file-uploads-message="Sorry, you can only upload 
up to 20 files at once." data-max-number-of-files="50" data-max-number-of-files-
message="This upload field only allows a maximum of 50 files." data-ui-
widget="file.Upload" data-ui-init="1" style="display:none">

【问题讨论】:

    标签: php yii


    【解决方案1】:

    files[] 更改为files。 通过拥有多个具有相同名称的表单元素,PHP 会将它们转换为数组。您不必(也不能)将它们视为 HTML 中的数组。

    因此,如果您有两个名称为 files 的输入,则可以使用 $_POST['files']$_GET['files'] 访问它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多