$_FILES is empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pdittman
Forum Newbie
Posts: 3
Joined: Tue Jun 24, 2008 5:21 am

$_FILES is empty

Post by pdittman »

I am writing a simple file upload script and seem unable to receive the uploaded file. My script is simple:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>File Upload Form</title>
</head>
<body>
This form allows you to upload a file to the server.<br>

<form action="<?=$me?>" method="post"><br>
Type (or select) Filename: <input type="file" name="userfile"><input type="submit" value="Upload File">
</form>

<?php
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
echo "GET method";
}
else {
print_r($_SERVER);
echo '<br />';
print_r($_FILES);
}
?>

</body>
</html>

My hosting service says there's an error with my script - I don't see it. This is the first time I've tried file upload on their systems.... Where's my error?

thanks in advance
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: $_FILES is empty

Post by jayshields »

Add:

Code: Select all

enctype="multipart/form-data"
to your form tag.

Ps. Do we still have HTML/CSS/SQL/etc. code tags? How do I use them?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: $_FILES is empty

Post by onion2k »

jayshields wrote:Add:

Code: Select all

enctype="multipart/form-data"
to your form tag.

Ps. Do we still have HTML/CSS/SQL/etc. code tags? How do I use them?
[ code=php ] [ /code ]
[ code=html ] [ /code ]
[ code=sql ] [ /code ]
etc..
pdittman
Forum Newbie
Posts: 3
Joined: Tue Jun 24, 2008 5:21 am

Re: $_FILES is empty

Post by pdittman »

Awesome! thanks!

-P
Post Reply