$_FILES empty when trying to do a file upload

2020-02-06 06:42发布

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>\n";

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.

标签: php
3条回答
相关推荐>>
2楼-- · 2020-02-06 07:23

Add that in Form tag

enctype="multipart/form-data"

查看更多
再贱就再见
3楼-- · 2020-02-06 07:32

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']
查看更多
时光不老,我们不散
4楼-- · 2020-02-06 07:41

You shuold use attribute enctype="multipart/form-data" in form tag.

查看更多
登录 后发表回答