uploading an image
Posted: Wed Sep 20, 2006 9:24 am
Hi, I have made a form that successfully passes all the variables required to upload an image file to a server.
The problem i now face is that no image file is actually uploaded!
I get the following two error messages:
Warning: move_uploaded_file(shop/product_images/image1.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/terrier/public_html/cms/shop/validate_product.php on line 22
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpNPqypi' to 'shop/product_images/image1.jpg' in /home/terrier/public_html/cms/shop/validate_product.php on line 22
I am stumped!
Below is the script used to upload the image file:
The problem i now face is that no image file is actually uploaded!
I get the following two error messages:
Warning: move_uploaded_file(shop/product_images/image1.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/terrier/public_html/cms/shop/validate_product.php on line 22
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpNPqypi' to 'shop/product_images/image1.jpg' in /home/terrier/public_html/cms/shop/validate_product.php on line 22
I am stumped!
Below is the script used to upload the image file:
Code: Select all
<?php
//CONNECT TO SERVER AND DATABASE
$link=mysql_connect("localhost", "terrier_andrew", "b1scarr0sse")
or die("Could not connect: " . mysql_error());
mysql_select_db("terrier_shopsmile32", $link)
or die(mysql_error());
//MAKE VARIABLES AVAILABLE
$prod_code = $_POST['p_code'];
$prod_name= $_POST['p_name'];
$prod_description = $_POST['p_desc'];
$image_tempname = $_FILES['p_image'] ['name'];
$prod_type = $_POST['p_type'];
$prod_unit_cost = $_POST['p_unit_cost'];
$prod_unit_price = $_POST['p_unit_price'];
$prod_stock_qty = $_POST['p_stock_qty'];
$ImageDir="shop/product_images/"; //$_SERVER['shop/product_images/'];
$ImageName=$ImageDir . $image_tempname;
if (move_uploaded_file($_FILES['p_image']['tmp_name'], $ImageName)){
//if (copy($_FILES['p_image'] ['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 was not a gif, jpg or png file.<br>";
echo "Please hit your browser's 'back' button and try again.";
}
$insert="INSERT INTO product
(product_id, prod_code, prod_name, prod_description, prod_image, prod_type, prod_unit_cost, prod_unit_price, prod_stock_qty)
VALUES
('$prod_code',
'$prod_code',
'$prod_name',
'$prod_description',
'$image_tempname',
'$prod_type',
'$prod_unit_cost',
'$prod_unit_price',
'$prod_stock_qty')";
$insertresults=mysql_query($insert)
or die(mysql_error());
$lastpicid=mysql_insert_id();
$newfilename=$ImageDir . $lastpicid . $ext;
rename($ImageName, $newfilename);
echo $newfilename . "added";
}
?>