访问它。
我试图给出允许的扩展程序,所以我确实尝试了此代码,但是我得到错误说
未定义的索引:文件[]
$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 Framework中的表单名称为文件[]
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">
将 files[]
更改为 files
。通过具有具有相同名称的多个表单元素,PHP将将其转换为数组。您不必(也不能)将它们视为html中的数组。
因此,如果您有两个带有files
名称的输入,则可以以$_POST['files']
或$_GET['files']
。