Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

php - $_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>

The second is the php file that handles it:

<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
<?php

print_r($_FILES);
print "<P>
";

move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
       "../blimages/site/7337/{$_FILES['uploadFile'] ['name']}")

?>
</body>
</html>

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.

The print_r($FILES) return a completely empty array.

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.

What else could be wrong?

Thanks,

Sean.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add the proper enctype attribute to your form tag:

<form action="getfile.php" method="post" enctype="multipart/form-data">

It's documented here: 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']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...