note 94662 rejected from function.move-uploaded-file by danbrown
| From: | danbrown@php.net | Date: | Tue, 17 Nov 2009 15:25:34 +0000 |
| Subject: | note 94662 rejected from function.move-uploaded-file by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162981@lists.php.net to get a copy of this message | ||
Note Submitter: misho_9222 at abv dot bg
----
O.K. I got this code from a book and i checked it for errors several times and I didn't find
anything.The page I get doesn't have an image or the other parameters of the image (type,
width....) and at the top of the page I get this error:
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function
cannot be a directory in E:\xampp\htdocs\check_image.php on line 14
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move
'E:\xampp\tmp\phpB0.tmp' to 'E://xampp/htdocs/images/' in
E:\xampp\htdocs\check_image.php on line 14
ERROR
<?php
$link=mysql_connect("localhost", "root", "")
or die ("Could not connect: " . mysql_error());
mysql_select_db("moviesite", $link)
or die(mysql_error());
//make variables available
$image_caption=$_POST['image_caption'];
$image_username=$_POST['image_username'];
$image_tempname=$_POST['image_filename']['name'];
$today=date("y-m-d");
//upload image and check type
$ImageDir="E://xampp/htdocs/images/";
$ImageName=$ImageDir . $image_tempname;
if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $ImageName)) {
list($width, $height, $type, $attr)=getimagesize($ImageName);
switch ($type) {
case 1:
$ext=".gif";
break;
case 2:
$ext=".jpg";
break;
case 3:
$ext=".png";
break;
default:
echo "Sorry, but the file you uploaded is not a GIF, JPG or PNG
file.<br>";
echo "Please hit your browser's 'back' button and try again.";
}
//inser info into image table
$insert="INSERT INTO images
(image_caption, image_username, image_date)
VALUES
('$image_caption', '$image_username', '$today')";
$insertresults=mysql_query($insert)
or die(mysql_error());
$lastpicid=mysql_insert_id();
$newfilename=$ImageDir . $lastpicid . $ext;
rename($Imagename, $newfilename);
} else { echo "ERROR"; }
?>
<html>
<head>
<title>
Here is your pic!
</title>
</head>
<body>
<h1>So how does it feek to be famous?</h1><br><br>
<p>Here is the picture you just uploaded to our servers:</p>
<img src="images/<?php echo $lastpicid . $ext; ?>" align="left"
alt="your image">
<strong><?php echo $image_name; ?></strong><br>
This image is a <?php echo $ext; ?> image.<br>
It is <?php echo $width; ?> pixels wide and
<?php echo $height; ?> pixels high.<br>
It was uploaded on <?php echo $today; ?>.
</body>
</html>
Please someone write me an e-mail with solution to the problem !!!
misho_9222@abv.bg