Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...