[英]PHP file uploading headache
I am having a tough time trying to upload files through PHP. 我很难通过PHP上传文件。
My form: 我的表格:
<form action="blah.php" enctype="multipart/form-data" method="post">
<p> Upload file: <input type="file" name="xmlfile"/>
<input type="submit" name="upload_submit" value="Upload" /> </p>
</form>
Checklist: 清单:
No 'smart' quotes in sight. 看不到“智能”报价。 Fine.
精细。
Proper enctype. 正确的enctype。 Fine.
精细。
name attrib in input tag. 输入标签中的名称属性。 Fine.
精细。
My /tmp
directory has the following permissions: drwxrwxrwt
. 我的
/tmp
目录具有以下权限: drwxrwxrwt
。 Fine. 精细。
post_max_size = 50M, upload_max_filesize = 50M, file_uploads = On. post_max_size = 50M,upload_max_filesize = 50M,file_uploads =开启。 Fine.
精细。
print_r($_FILES)
gives Array()
. print_r($_FILES)
给出Array()
。 Useless. 无用。 Tried on images, xml files, etc. Nothing works.
在图像,xml文件等上尝试过。没有任何效果。
What I don't understand even further is that there are pages on which file uploading works on the same server. 我什至不了解的是,有些页面上的文件上载在同一服务器上。 The only thing different from what I can gather is that the page I am working on has a few other forms which aren't of
enctype="multipart/form-data"
. 与我能收集到的唯一不同的是,我正在处理的页面还有其他几种形式,它们不是
enctype="multipart/form-data"
。 Should this matter? 这应该重要吗?
PHP code as requested: 要求的PHP代码:
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if(isset($_POST['upload_submit'])){
print_r($_FILES);
exit();
...
}
}
Gives an empty array regardless of print_r
's position; 给出一个空数组,而不管
print_r
的位置如何; I also tried it right after the if($_SERVER['REQUEST_METHOD'] == 'POST'){
我还在
if($_SERVER['REQUEST_METHOD'] == 'POST'){
Are you sure that you are submitting the right form or you are dealing with the submitted data in the right place/script? 您确定要提交正确的表格或正在正确的位置/脚本中处理提交的数据吗? Provide some of the PHP code please.
请提供一些PHP代码。
your from, this php script (as blah.php) 您来自此php脚本(如blah.php)
edit for debugging, dump $_POST
if
is false
编辑以进行调试,
if
为false
,则转储$_POST
error_reporting(E_STRICT);
ini_set('display_errors', 'on');
if(array_key_exists('xmlfile', $_FILES)) {
echo 'file ' , $_FILES['xmlfile']['name'] , ' recieved';
echo '<pre>'
, print_r($_POST, true)
, print_r($_FILES, true)
, '</pre>';
} else {
echo '<pre>'
, print_r($_POST, true)
, '</pre>';
}
(possible) output: (可能)输出:
file rapid-gui-development-with-qtruby_p1_4.mobi recieved
Array
(
[upload_submit] => Upload
)
Array
(
[xmlfile] => Array
(
[name] => rapid-gui-development-with-qtruby_p1_4.mobi
[type] => application/octet-stream
[tmp_name] => /private/tmp/phpEyV3vy
[error] => 0
[size] => 556846
)
)
You mention having other forms on the page... are those properly closed? 您提到页面上还有其他表格...这些表格正确关闭了吗? For instance, if you have:
例如,如果您有:
<form method="post">
blah blah blah
<input type="submit" />
<!-- oops forgot to </form> here -->
<form method="post" enctype="multipart/form-data">
...
<input type="submit" />
</form>
Then the FIRST <form>
tag could be taking precendence and submitting without the enctype set. 然后,FIRST
<form>
标记可以在没有enctype设置的情况下取得优势并提交。
If you're on Firefox, I'd suggest using Firebug/HTTPFox/LiveHTTPHeaders (all available in FF's add-ons library) to see what's being sent over the wire, and running your page through a validator to make sure there's no goofy HTML bugs causing this. 如果您使用的是Firefox,建议您使用Firebug / HTTPFox / LiveHTTPHeaders(全部在FF的附加组件库中提供)以查看通过网络发送的内容,并通过验证程序运行页面以确保没有多余的HTML导致此的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.