note 52300 added to features.file-upload
| From: | Sa_Estahbanatiatyahoodotcom at osu1 dot php dot net | Date: | Wed, 27 Apr 2005 12:47:58 +0000 |
| Subject: | note 52300 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88619@lists.php.net to get a copy of this message | ||
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>";
?>
----
Manual Page -- http://www.php.net/manual/en/features.file-upload.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52300
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52300&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52300&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52300&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52300&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52300&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52300&report=yes
Search -- http://master.php.net/manage/user-notes.php