I am trying to make an upload script for the first time, and I don't get it.
I have trying copying the script from the PHP manual, but I can't get it to work.
As it lookes right now I have a script looking like this, a direct copy from the manual :
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="test.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
When I run the site I see a form box with a browse button. I then browse a .txt file from my harddrive, and press 'send file'
i then get the message:
Warning: move_uploaded_file() [function.move-uploaded-file]: SAFE MODE Restriction in effect. The script whose uid/gid is 1638/80 is not allowed to access /var owned by uid/gid 0/0 in /usr/home/web/web60269/TEST/test.php on line 28
Possible file upload attack!
Here is some more debugging info:Array
(
[userfile] => Array
(
[name] => bring.txt
[type] => text/plain
[tmp_name] => /var/tmp/phpKhNDMU
[error] => 0
[size] => 965
)
)
I can see that the [tmp_name] => /var/tmp/phpKhNDMU line changes when I try to upload again, so it seems like it's trying to upload the file with a tmp name, but when I check, there are no files uploaded.
I'm not sure where the files are stored so I have made a dir called /var/www/uploads and one just called uploads and they are all set to chmod 777.
But still nothing happens.
What am I doing wrong, and where in script is the moved file name entered ?
Please help me get startet.
Michael