image upload
Posted: Tue Mar 14, 2006 7:38 pm
Hi,
I am having difficulties trying to upload an image file.
I am using an html form as data entry for selecting the image.
Below is the php code i am using to upload the selected image file to my database:
The above code results in the following error:
Warning: rename(c:/Program Files/Apache Group/Apache2/test/ace_cart/admin/images/,c:/Program Files/Apache Group/Apache2/test/ace_cart/admin/images/0) [function.rename]: Permission denied in C:\Program Files\Apache Group\Apache2\test\ace_cart\admin\check_product.php on line 61
I tried to just echo the image file at line 14 and nothing was echoed!!!
Any help would be much appreciated,
Nick
I am having difficulties trying to upload an image file.
I am using an html form as data entry for selecting the image.
Below is the php code i am using to upload the selected image file to my database:
Code: Select all
<?php
//CONNECT TO SERVER AND DATABASE
include "conn.inc.php";
//MAKE VARIABLES AVAILABLE
$prod_code = $_POST['prod_code'];
$prod_name= $_POST['prod_name'];
$prod_description = $_POST['prod_description'];
$prod_image = $_FILES['prod_image'] ['name'];
$prod_type = $_POST['prod_type'];
$prod_unit_cost = $_POST['prod_unit_cost'];
$prod_unit_price = $_POST['prod_unit_price'];
$prod_stock_qty = $_POST['prod_stock_qty'];
//UPLOAD PRODUCT AND CHECK FOR IMAGE TYPE
//CHANGE IMAGE PATH TO MATCH DIR
$ImageDir = "c:/Program Files/Apache Group/Apache2/test/ace_cart/admin/images/";
$ImageName = $ImageDir . $prod_image;
if (move_uploaded_file($_FILES['prod_image'] ['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 PRODUCT INTO PRODUCT TABLE
$insert = "INSERT INTO product
(prod_code, prod_name, prod_description, prod_image, prod_type, prod_unit_cost, prod_unit_price, prod_stock_qty)
VALUES
('$prod_code',
'$prod_name',
'$prod_description',
'$prod_image',
'$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);
?>Warning: rename(c:/Program Files/Apache Group/Apache2/test/ace_cart/admin/images/,c:/Program Files/Apache Group/Apache2/test/ace_cart/admin/images/0) [function.rename]: Permission denied in C:\Program Files\Apache Group\Apache2\test\ace_cart\admin\check_product.php on line 61
I tried to just echo the image file at line 14 and nothing was echoed!!!
Any help would be much appreciated,
Nick