Jump to content

Plaincart image won't display


drax

Recommended Posts

I wonder if someone could help me with the below

 

I am working through trying to set up a website using a pre built shopping cart(http://www.phpwebcommerce.com.)

Have installed fine and set up my categories of products (with images.) However when i try and add a product itself, it will not display the image i assign to it - it just remains blank on both the screen and the mysql database

 

The code for the working image upload is

 

function uploadImage($inputName, $uploadDir)
{
    $image     = $_FILES[$inputName];
    $imagePath = '';
    
    // if a file is given
    if (trim($image['tmp_name']) != '') {
        // get the image extension
        $ext = substr(strrchr($image['name'], "."), 1); 

        // generate a random new file name to avoid name conflict
        $imagePath = md5(rand() * time()) . ".$ext";
        
	// check the image width. if it exceed the maximum
	// width we must resize it
	$size = getimagesize($image['tmp_name']);

	if ($size[0] > MAX_CATEGORY_IMAGE_WIDTH) {
		$imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_CATEGORY_IMAGE_WIDTH);
	} else {
		// move the image to category image directory
		// if fail set $imagePath to empty string
		if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) {
			$imagePath = '';
		}
	}	
    }

    
    return $imagePath;
}

 

 

and thew code for the one that does not work is

 

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";
            $result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
            
            // 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);
} 

 

 

I've tired replacing the product code with the catagorey code. This almost works , as the shows in the db but still does not display in explorer.

 

Sorry if this is unclear but it is driving me insane, as no-one else seems to have had this problem with the tutorial

 

Thanks in advance for any help

 

drax

Link to comment
Share on other sites

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.