为什么将文件上传到 PHP 时 $_FILES 会为空? [英] Why would $_FILES be empty when uploading files to PHP?

查看:21
本文介绍了为什么将文件上传到 PHP 时 $_FILES 会为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Windows 7 计算机上安装了 WampServer 2.我使用的是 Apache 2.2.11 和 PHP 5.2.11.当我尝试从表单上传任何文件时,它似乎上传,但在 PHP 中,$_FILES 数组为空.c:\wamp\tmp 文件夹中没有文件.我已将 php.ini 配置为允许文件上传等.tmp 文件夹对当前用户具有读/写权限.我被难住了.

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";
?>

推荐答案

感谢大家的各种全面回复.这些都是非常有帮助的.结果发现答案很奇怪.事实证明,PHP 5.2.11 不喜欢以下内容:

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

post_max_size = 2048M

如果我将其更改为 2047M,则上传有效.

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

这篇关于为什么将文件上传到 PHP 时 $_FILES 会为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆