hi there,
i have file upload problem for the shopping cart.
its windows server. directory permission are set.
ACL = everyone -> RED/WRITE/EXE
can you please help me, or suggest me better version of this script.
NOTE:
the script works just fine on linux server.
please help,
Thank you.
my code for upload is:
<?php
include("../includes/db.conf.php");
include("../includes/connect.inc.php");
include ("../includes/functions.inc.php");
echo "<html><body bgcolor='#cccccc'><font face='verdana'><center>";
if (isset($_POST['submit'])){
if (file_exists($_FILES['image']['tmp_name'])){
$photoname=$_FILES['image']['name'];
move_uploaded_file ($_FILES['image']['tmp_name'],"../images/".$photoname);
thumbnail("../images/","../images/thumbs/",$photoname,100);
//$rowa=mysql_fetch_array($mysqlresulta);
}else{
$photoname="nophoto.jpg";
}
$queryn="INSERT into products set name='$_POST[pname]', photo='$photoname', description='$_POST[description]', price='$_POST[price]', category='$_POST[category]', quantity='$_POST[quantity]'";
$mysqlresultn = mysql_query($queryn);
echo "New Product Added<br>";
echo mysql_error();
}
echo "<h3>Add New Product</h3>";
echo "<form action='addproduct.php' method='post' enctype='multipart/form-data'> ";
echo "<table>";
echo "<tr><td>Product Name</td>";
echo "<td><input name='pname' type='text' size='25' /></td></tr>";
echo "<tr><td colspan=2>Description</td></tr>";
echo "<tr><td colspan=2><textarea name='description' cols='30' rows='5'></textarea></td></tr>";
echo "<tr><td>Price</td>";
echo "<td><input type='text' name='price'></td></tr>";
echo "<tr><td>Photo</td>";
echo "<td><input type='file' name='image'></td></tr>";
echo "<tr><td>Category</td>";
echo "<td><select name='category'>";
$query = "SELECT * from categories ";
$mysqlresult = mysql_query($query);
while($row = mysql_fetch_array($mysqlresult)){
echo "<option value='$row[id]'>$row[name]</option>";
}
echo "<select></td></tr>";
echo "<tr><td>Quantity</td>";
echo "<td><input type='text' name='quantity'></td></tr>";
echo "<tr><td colspan=2><input type='submit' name='submit' value='Submit'></td></tr>";
echo "</table>";
echo "</body></html>";
?>
file that we include:
functions.inc.php
<?php
function thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
{
$system=explode(".",$image_name);
if (!preg_match("/gif/",$system[1])){
if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg("$image_path/$image_name");}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng("$image_path/$image_name");}
//$src_img = imagecreatefromjpeg("$image_path/$image_name");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
if ($origh>$origw){
$new_h=120;
$new_w=120*($origw/$origh);
}else{
$new_w=120;
$new_h=120*($origh/$origw);}
//$new_w = $thumb_width;
//$diff=$origw/$new_w;
//$new_h=$new_w;
//$dst_img = imagecreate($new_w,$new_h);
//imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
$dst_img = ImageCreateTrueColor($new_w,$new_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
if (preg_match("/png/",$system[1])){
imagepng($dst_img,"$thumb_path/$image_name");
} elseif (preg_match("/jpg|jpeg/",$system[1])){
imagejpeg($dst_img,"$thumb_path/$image_name");
}else{
imagegif($dst_img,"$thumb_path/$image_name");
}
//imagejpeg($dst_img, "$thumb_path/$image_name");
return true;
}else{
echo "You can only upload jpg and png files.<br>\n";
}
}
?>