$_FILES array in PHP is empty

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 00:51:05

When you have the proper enctype(<form method="post" enctype="multipart/form-data">), then check the errno variable in $_FILES, there are various possible causes for a failure. Typical is MAX_FILE_SIZE being exceeded.

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

Since PHP 4.2.0, PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].

UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success.

UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

etc.

Are you defining the enctype in your form ?

<form method="post" enctype="multipart/form-data">

No file will be uploaded if you don't set it.

Does the form have the right enctype?

enctype="multipart/form-data"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!