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:21

Ensure your form has the following attribute enctype="multipart/form-data".

查看更多
荒废的爱情
3楼-- · 2018-12-31 04:22

If you are trying to upload an array of files then you may need to increase max_file_uploads in php.ini which is by default set to 20

Note: max_file_uploads can NOT be changed outside php.ini. See PHP "Bug" #50684

查看更多
姐姐魅力值爆表
4楼-- · 2018-12-31 04:24

Make sure your input element has a 'name' attribute. <input type="file" name="uploadedfile" />

If this is missing the $_FILES will be empty.

查看更多
裙下三千臣
5楼-- · 2018-12-31 04:24

I ran into the same issue and found that it was my IDE was part of the issue. I was launching the debugger directly from the IDE (PHPStorm) instead of just using the browser directly. The IDE spawned URL was like this:

"...localhost:63342/CB_Upload/index.php?_ijt=j2hcbacqepj87bvg66ncuohvne"

and just using:

"...localhost/CB_Upload/index.php"

worked just fine. My set up is PC / Windows 10 / WAMPSERVER 3.0.6 64bit

查看更多
路过你的时光
6楼-- · 2018-12-31 04:27

As far as the HTML you appear to have set that part up correctly. You already have the enctype="multipart/form-data" which is very important to have on the form.

As far as your php.ini setup, sometimes on systems multiple php.ini files exist. Be sure you are editing the correct one. I know you said you have configured your php.ini file to have file uploads, but did you also set your upload_max_filesize and post_max_size to be larger than the file you are trying to upload? So you should have:

file_uploads = On; sounds like you already did this
post_max_size = 8M; change this higher if needed
upload_max_filesize = 8M; change this higher if needed

Does your directory: "c:\wamp\tmp" have both read and write permissions? Did you remember to restart Apache after you made the php.ini changes?


查看更多
不流泪的眼
7楼-- · 2018-12-31 04:27

I too had problems with $_FILES empty. The above check-list do not mention MultiViews in .htaccess, httpd.conf or httpd-vhost.conf.

If you have MultiViews set in the options directive for your directory containing the web site, $_FILES will be empty, even though Content-Length header if showing that the file i uploaded.

查看更多
登录 后发表回答