I am building an online photo directory for a cousin of mine. Each user will be able to upload an image. The books and websites I have read on how to do this use the $_FILES array or something similar.
Consider the following form as an example:
<form action="<?php $_SERVER['PHP_SELF'] ?>" enctype="multi-part/form-data" method="post">
<input type=file name="userfile">
<input type=submit>
</form>
Some of my books say that when a file is specified and the form posted, PHP will create a few variables. In this example they should be:
$userfile, $userfile_name, $userfile_type, and $userfile_size
These should also be able to be accessed with the following:
$FILES['userfile']['name'];
$FILES['userfile']['type'];
$_FILES['userfile']['size'];
I can't seem to access these variables, they have no values. Below is a simple test script I have been trying to get working:
<?php
if(!empty($_POST['userfile']))
{
$filename = $_FILES['userfile']['name'];
$filetype = $_FILES['userfile']['type'];
$filesize = $_FILES['userfile']['size'];
//Should print out variable values to screen
echo "filename: $filename<br>",
"filetype: $filetype<br>",
"filesize: $filesize<br>";
}
?>
<form action="<?php $_SERVER['PHP_SELF'] ?>" enctype="multi-part/form-data" method="post">
<input type=file name="userfile">
<input type=submit>
</form>
When I post this form, with a specified file as "userfile", php prints
filename:
filetype:
filesize:
to the screen - with no values. Does anyone know why no values are appearing? The books have become useless as they all assume the above code works. Any feedback would be appreciated. Thanks.
David