尝试上传文件时,$ _ FILES为空 [英] $_FILES empty when trying to do a file upload
问题描述
这让我发疯.我试图弄清楚如何上传文件.我有两个非常简单的文件,但似乎不起作用.首先是允许用户选择文件的文件:
This is driving me crazy. I'm trying to figure out how to upload a file. I've got two very simple files, yet it doesn't seem to work. This first is the file that allows the user to choose the file:
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>
<form action="getfile.php" method="post"><br>
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="submit" value="Upload File">
</form>
</body>
</html>
</code>
第二个是处理它的php文件:
The second is the php file that handles it:
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php
print_r($_FILES);
print "<P>\n";
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../blimages/site/7337/{$_FILES['uploadFile'] ['name']}")
?>
</body>
</html>
由于-除了print_r
-我从网站教程中了解了如何进行文件上传,所以我认为这些文件还可以.
Since -- except for the print_r
-- I pulled these off a website tutorial on how to do a file upload, I'd think these files are okay.
print_r($FILES)
返回一个完全为空的数组.
The print_r($FILES)
return a completely empty array.
我还检查了php.ini
.允许上传文件,最大大小为2M,我假设为2兆字节,这远远大于我一直尝试上传的文件.
I also checked the php.ini
. File uploads are allowed, and the max size is 2M, which I assume is 2 megabytes, which is far larger than the file I've been trying to upload.
还有什么问题吗?
谢谢
西恩.
推荐答案
在您的form
标签中添加适当的enctype属性:
Add the proper enctype attribute to your form
tag:
<form action="getfile.php" method="post" enctype="multipart/form-data">
在此处记录: http://www. php.net/manual/en/features.file-upload.post-method.php
此外,访问多维数组时,请确保括号之间没有空格:
Also, make sure there's no space between your brackets when you access multi-dimensional arrays:
$_FILES['uploadFile']['tmp_name']
这篇关于尝试上传文件时,$ _ FILES为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!