RE: [PHP] Upload File Problem
| From: | joakim dot andersson at cybercom dot se | Date: | Thu, 18 Jul 2002 09:24:40 +0000 |
| Subject: | RE: [PHP] Upload File Problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-108227@lists.php.net to get a copy of this message | ||
> From: Mark Colvin [mailto:mark.colvin@ccmltd.co.uk]
> Sent: Thursday, July 18, 2002 10:09 AM
>
> -- upload.php --
> <?php
>
> if ('img1' != "") {
This will allways be true! 'img1' is a string and will never be empty.
You probably mean if($img1 != "")
However, I'm not sure this will work in this case.
Try this instead. (Taken straight from the PHP-manual. A real good
resource!)
<?php
if (is_uploaded_file($_FILES['img1']['tmp_name']))
{
$filename = $_FILES['img1']['tmp_name'];
print "$filename was uploaded successfuly";
$realname = $_FILES['img1']['name'];
print "realname is $realname";
print "copying file to uploads dir";
copy($_FILES['img1']['tmp_name'], "/place/to/put/" . $realname);
}
else
{
echo "Possible file upload attack: filename" .
$_FILES['img1']['name'] . ".";
}
?>
If you use PHP < 4.1.0 you must exchange $_FILES to $HTTP_POST_FILES
Regards
Joakim Andersson