I having troublw with uploading images,
this is the script that I use along with the function of the process and the display page of the product!
function copyImage($srcFile, $destFile, $w, $h, $quality = 75)
{
$tmpSrc = pathinfo(strtolower($srcFile));
$tmpDest = pathinfo(strtolower($destFile));
$size = getimagesize($srcFile);
if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
{
$destFile = substr_replace($destFile, 'jpg', -3);
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
} elseif ($tmpDest['extension'] == "png") {
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
} else {
return false;
}
switch($size[2])
{
case 1: //GIF
$src = imagecreatefromgif($srcFile);
break;
case 2: //JPEG
$src = imagecreatefromjpeg($srcFile);
break;
case 3: //PNG
$src = imagecreatefrompng($srcFile);
break;
default:
return false;
break;
}
imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
switch($size[2])
{
case 1:
case 2:
imagejpeg($dest,$destFile, $quality);
break;
case 3:
imagepng($dest,$destFile);
}
return $destFile;
}
function addProduct()
{
$images = uploadProductImage('fileImage', SRV_ROOT . '.../www/plaincart/images/product/');
$mainImage = $images['image'];
$thumbnail = $images['thumbnail'];
$sql = "INSERT INTO tbl_product (pd_image, pd_thumbnail,)
VALUES ('$mainImage', '$thumbnail', NOW())";
$result = dbQuery($sql);
header("Location: index.php?catId=$catId");
}
<?php
$parentId = 0;
if (dbNumRows($result) > 0) {
$i = 0;
while($row = dbFetchAssoc($result)) {
extract($row);
if ($pd_thumbnail) {
$pd_thumbnail = WEB_ROOT . '/images/product/' . $pd_thumbnail;
} else {
$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
//this is the only image I get
}
if ($i%2) {
$class = 'row1';
} else {
$class = 'row2';
}
$i += 1;
?>