Jump to content

Recommended Posts

hi

In the following posted code(add products at admin side)

i inserted the following lines of code,

echo $images; at line 10

echo $mainimage; at line 14

echo $thumbnail; at line 15

echo $thumbnailpath; at line 56

echo $result; at line 58

 

I get error ,i cannot see the output..

what are the correct codes..??

 

function addProduct()
{
    $catId       = $_POST['cboCategory'];
    $name        = $_POST['txtName'];
$description = $_POST['mtxDescription'];
$price       = str_replace(',', '', (double)$_POST['txtPrice']);
$qty         = (int)$_POST['txtQty'];

$images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/');
echo $images;

$mainImage = $images['image'];
$thumbnail = $images['thumbnail'];
echo $mainimage;
echo $thumbnail;

$sql   = "INSERT INTO tbl_product (cat_id, pd_name, pd_description, pd_price, pd_qty, pd_image, pd_thumbnail, pd_date)
          VALUES ('$catId', '$name', '$description', $price, $qty, '$mainImage', '$thumbnail', NOW())";

$result = dbQuery($sql);

header("Location: index.php?catId=$catId");	
}

/*
Upload an image and return the uploaded image name 
*/
function uploadProductImage($inputName, $uploadDir)
{
$image     = $_FILES[$inputName];
$imagePath = '';
$thumbnailPath = '';

// if a file is given
if (trim($image['tmp_name']) != '') {
	$ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']];

	// generate a random new file name to avoid name conflict
	$imagePath = md5(rand() * time()) . ".$ext";

	list($width, $height, $type, $attr) = getimagesize($image['tmp_name']); 

	// make sure the image width does not exceed the
	// maximum allowed width
	if (LIMIT_PRODUCT_WIDTH && $width > MAX_PRODUCT_IMAGE_WIDTH) {
		$result    = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_PRODUCT_IMAGE_WIDTH);
		$imagePath = $result;

	} else {
		$result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
	}	

	if ($result) {
		// create thumbnail
		$thumbnailPath =  md5(rand() * time()) . ".$ext";
echo $thumbnailpath;
		$result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
echo $result;			
		// create thumbnail failed, delete the image
		if (!$result) {
			unlink($uploadDir . $imagePath);
			$imagePath = $thumbnailPath = '';
		} else {
			$thumbnailPath = $result;
		}	
	} else {
		// the product cannot be upload / resized
		$imagePath = $thumbnailPath = '';
	}

}


return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
}

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/174178-how-to-get-the-output/
Share on other sites

hi

 

this is processcategory file of a shopping cart in admin/product folder.

when the admin add a product(name, description etc) in the add product form,and after clicking the "add product" button,this file gets into action

 

I wish to see the values stored in $images,$mainimage,$thumbnail,$thumbnailpath etc..(to check what is stored..)as told in above..

eg. $a=5;

i can see it using echo $a;

 

I dont get errors...but i cannot see the value displayed when running the file or project...so could  you give me the soultion...

 

Despite the bark of orders to 'find the solution' for you, you've given a big chunk of fairly complex looking code (may well not be) with little explanation and no code to show how these functions are called.. that I'm sure no one *wants* to work their way through and find what your problem is.. without a little please and thank you at least.

at the end of the function, you have

 header("Location: index.php?catId=$catId");

which is loading a new page, so the echo's are not staying on the screen long enough to be seen.

 

You'll either have to echo to a log file and read it later, or comment out the header (for testing) and echo out an HTML link.  Then you can read the screen, and then click the link to continue processing to the next page.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.