Page 1 of 1

$_FILES is empty

Posted: Tue Jun 24, 2008 5:27 am
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

Re: $_FILES is empty

Posted: Tue Jun 24, 2008 5:59 am
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?

Re: $_FILES is empty

Posted: Tue Jun 24, 2008 6:13 am
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..

Re: $_FILES is empty

Posted: Tue Jun 24, 2008 6:23 am
by pdittman
Awesome! thanks!

-P