note 52300 deleted from features.file-upload by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 17:51:29 +0000 |
| Subject: | note 52300 deleted from features.file-upload by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134317@lists.php.net to get a copy of this message | ||
Note Submitter: Sa_Estahbanati at yahoo dot com
----
In the above notes there was solution to the server-side code that would use move_uploaded_file() to
save the temporary file into a permanent path.
A pal maitaned that relative path would have problem in windows servers and you should indicate the
complete path instead. While it is almost impossible to ge to know the exact path when you are not
the host, I tried to test other ways and finally found out that a simple "." (dot) before
tha path would solve the relative pathing problem.
instead of '/var/www/uploads/' or 'E:/sitebase/var/www/uploads/' you should type
'./var/www/uploads/'
Here is the complete source:
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
//$uploaddir = 'E:/sitebase/var/www/uploads/';
//$uploaddir = '/var/www/uploads/';
$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>";
?>