Warning: move_uploaded_file(C:/projects/pratice/WWW/ch07/images/) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\projects\pratice\WWW\ch07\check_image.php on line 17
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpD9.tmp' to 'C:/projects/pratice/WWW/ch07/images/' in C:\projects\pratice\WWW\ch07\check_image.php on line 17
I know it has something to do with my path but I can't figure out how to fix it. Here is my code:
Code: Select all
<?php
//connect to db
require_once('dbconnection.php');
//pull var from form
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_POST['image_filename'];
$today = date("Y-m-d");
//upload image and check for image type
//path not working
$imageDir = "C:/projects/pratice/WWW/ch07/images/";
$imageName = $imageDir . $image_tempname;
//check to see if file is valid upload file (uploaded by post)
if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $imageName))
{
//get info about the image being uploaded
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 was not a GIF,
JPG, or PNG file <br />";
echo "Please hit your browser's 'back' button and try again";
}
//insert 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);
}
?>
<html>
<head>
<title>Here is your pic</title>
</head>
<body>
<h1>So how does it feel 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">
<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>