$_FILES array in PHP is empty

2020-04-13 20:14发布

I'm trying to get a file uploaded through a PHP script, but my $_FILES array is always empty? My $_POST data entry for the file HTML input element has the filename...Just no file is created on my local system.

I've verified write access to the temp folder and explicity set it. I've checked phpinfo() to make sure file uploads are enabled, and they are.

What could be preventing this? Would mod_rewrite cause anything?

Thanks!

3条回答
Explosion°爆炸
2楼-- · 2020-04-13 20:45

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.

查看更多
淡お忘
3楼-- · 2020-04-13 20:57

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.

查看更多
叼着烟拽天下
4楼-- · 2020-04-13 21:01

Does the form have the right enctype?

enctype="multipart/form-data"
查看更多
登录 后发表回答