Sean Sean - 8 months ago 39
PHP Question

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

<title>File Upload Form</title>
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">

The second is the php file that handles it:

<title>Process Uploaded File</title>

print "<P>\n";

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


Since -- except for the
-- I pulled these off a website tutorial on how to do a file upload, I'd think these files are okay.

return a completely empty array.

I also checked the
. 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?



Answer Source

Add the proper enctype attribute to your form tag:

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

It's documented here:

Also, make sure there's no space between your brackets when you access multi-dimensional arrays:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download