Why would $_FILES be empty when uploading files to

2018-12-31 03:56发布

I have WampServer 2 installed on my Windows 7 computer. I'm using Apache 2.2.11 and PHP 5.2.11. When I attempt to upload any file from a form, it seems to upload, but in PHP, the $_FILES array is empty. There is no file in the c:\wamp\tmp folder. I have configured php.ini to allow file uploads and such. The tmp folder has read/write privileges for the current user. I'm stumped.

HTML:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <form enctype="multipart/form-data" action="vanilla-upload.php" method="POST">
        Choose a file to upload: <input name="uploadedfile" type="file" /><br />
        <input type="submit" value="Upload File" />
    </form>
</body>
</html>

PHP:

<?php
echo 'file count=', count($_FILES),"\n";
var_dump($_FILES);
echo "\n";
?>

20条回答
还给你的自由
2楼-- · 2018-12-31 04:38

No one mentioned this but it helped me out and not many places on the net mention it.

Make sure your php.ini sets the following key:

    upload_tmp_dir="/path/to/some/tmp/folder"

You'll need to check with your webhost if they want you to use an absolute server file path. You should be able to see other directory examples in your php.ini file to determine this. As soon as I set it I got values in my _FILES object.

Finally make sure that your tmp folder and wherever you are moving files to have the correct permissions so that they can be read and written to.

查看更多
像晚风撩人
3楼-- · 2018-12-31 04:38

I got the same problem and none of theme was my error. Check in your .htaccess file, if you got one, if "MultiViews" are enabled. I had to disable them.

查看更多
孤独总比滥情好
4楼-- · 2018-12-31 04:39

I had similar problem and the issue was in wrong value in htaccess as shamittomar mentioned.

Change php_value post_max_size 10MB to php_value post_max_size 10M

查看更多
春风洒进眼中
5楼-- · 2018-12-31 04:43

I have a same problem looking 2 hours ,is very simple to we check our server configuration first.

Example:

echo $upload_max_size = ini_get('upload_max_filesize');  
echo $post_max_size=ini_get('post_max_size');   

any type of file size is :20mb, but our upload_max_size is above 20mb but array is null. Answer is our post_max_size should be greater than upload_max_filesize

post_max_size = 750M  
upload_max_filesize = 750M
查看更多
初与友歌
6楼-- · 2018-12-31 04:45

Here another cause I found: When using JQuery Mobile and the form attribute data-ajax is set to true, the FILES array will be empty. So set data-ajax to false.

查看更多
倾城一夜雪
7楼-- · 2018-12-31 04:46

Thank you everybody for the vary comprehensive replies. Those are all very helpful. The answer turned out to be something very odd. It turns out that PHP 5.2.11 doesn't like the following:

post_max_size = 2G

or

post_max_size = 2048M

If I change it to 2047M, the upload works.

查看更多
登录 后发表回答