Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how can i make OSC check if image don't exist


Guest

Recommended Posts

Posted

i have 22,000 items which i upload using excel and easy populate.

 

excel assume an image link for all the items even though some of the items picture does not exist.

 

any other ideas how to do this?

 

i just dont want items w/o picture to show on the website.

 

 

i googled and found a post like this

 

I created an .htaccess file with the following line of code:
ErrorDocument 404 /404.php

I then created a file named 404.php with this code snippet:
if (preg_match("/[0-9]*_thumb\.png/", $_SERVER[REQUEST_URI])) {
header("Location: /house_images/_thumb.png");
exit;
}

 

i think what it does is check if the thumb exist, if not it will show a specific thumbnail. maybe we can use this function to set item to inactive if image does not exist.

 

i appreciate any help =)

Posted

Instead of using a 404 script it would be better to put the logic in the tep_image() function located in includes/functions/html_output.php

 

Find this code:

	if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
  return false;
}

ABOVE it paste this code:

	if ( is_dir(rtrim(DIR_FS_CATALOG, '/') . '/' . $src) || !file_exists(rtrim(DIR_FS_CATALOG, '/') . '/' . $src) ){
	$sql = "UPDATE " . TABLE_PRODUCTS . " SET products_status = '0' WHERE products_image IS NULL OR products_image = '".basename($src)."'";
	$query = tep_db_query($sql);
	return false;
}

Posted

thank you for your help i really appriciate it.

 

im still tryin to get your code to work for me since my html_output.php is different now

 

here is the function for the image wrapper in my html_output.php

function tep_image($src, $alt = '', $width = '', $height = '', $params = '') {

// devx's code start 

		if ( is_dir(rtrim(DIR_FS_CATALOG, '/') . '/' . $src) || !file_exists(rtrim(DIR_FS_CATALOG, '/') . '/' . $src) ){
	$sql = "UPDATE " . TABLE_PRODUCTS . " SET products_status = '0' WHERE products_image IS NULL OR products_image = '".basename($src)."'";
	$query = tep_db_query($sql);
	return false;
  }
//devx's code end

// Set default image variable and code
	$image = '<img src="' . $src . '"';

// Don't calculate if the image is set to a "%" width
	if (strstr($width,'%') == false || strstr($height,'%') == false) {
	$dont_calculate = 0;
} else {
	$dont_calculate = 1;
	}

// Do we calculate the image size?
	if (CONFIG_CALCULATE_IMAGE_SIZE && !$dont_calculate) {

	// Get the image's information
			if ($image_size = @getimagesize($src)) {

				$ratio = $image_size[1] / $image_size[0];

				// Set the width and height to the proper ratio
					if (!$width && $height) {
			$ratio = $height / $image_size[1];
			$width = intval($image_size[0] * $ratio);
		} elseif ($width && !$height) {
			$ratio = $width / $image_size[0];
			$height = intval($image_size[1] * $ratio);
		} elseif (!$width && !$height) {
			$width = $image_size[0];
			$height = $image_size[1];
		}

		// Scale the image if larger than the set width or height
					if ($image_size[0] > $width || $image_size[1] > $height) {
			$rx = $image_size[0] / $width;
			$ry = $image_size[1] / $height;

			if ($rx < $ry) {
				$width = intval($height / $ratio);
			} else {
				$height = intval($width * $ratio);
			}

			$image = '<img src="product_thumb.php?img='.$src.'&w='.tep_output_string($width).'&h='.tep_output_string($height).'"';
		}

	} elseif (IMAGE_REQUIRED == 'false') {
		  return '';
	}

}

// Add remaining image parameters if they exist
	if ($width) {
	$image .= ' width="' . tep_output_string($width) . '"';
}

if ($height) {
	$image .= ' height="' . tep_output_string($height) . '"';
}

if ($params != '') {
	$image .= ' ' . $params;
}

$image .= ' border="0" alt=" ' . tep_output_string($alt) . ' "';

	if ($alt)
	$image .= ' title=" ' . tep_output_string($alt) . ' "';

$image .= '>';

return $image;
}

Posted
...the database update would be better performed from the admin side rather than the catalog side.

The only issue with that is the store owner is using Easy Populate to upload the products. The tep_image() function won't be called until they edit the product via the adminCP. Thus, if there are 22,000 products uploaded (as the store owner mentioned) they would have to edit each product at least once (even if no changes are actually made).

 

In the name of time saving measures I would probably put the code into a function, save it in the admin/includes/functions/general.php and then include (call) it at the bottom of the Easy Populate script.

 

function fixImages(){
ini_set('max_execution_time', 0);
$sql = "SELECT products_id as id, products_image as image FROM " . TABLE_PRODUCTS;
$query = tep_db_query($sql);
while($result = tep_db_query($query)){
	if ( !tep_not_null($result['image']) || !file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $result['image']) ){
		$updatesql = "UPDATE " . TABLE_PRODUCTS . " SET products_status = '0' WHERE products_id = '".(int)$result['id']."'";
		$updatequery = tep_db_query($updatesql);
		tep_db_free_result($updatequery);			
	}
}
tep_db_free_result($query);
} # end function

Posted

sorry for my poor php.. but i try to add the function fixImages() in the admin/includes/functions/general.php and call it by adding fixImages() (correct me if thats not the right way to call the function) at the end of EasyPopulate but still no luck and it shows this message

 

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #87' at line 1

 

Resource id #87

 

[TEP STOP]

Posted

Simple mistake...use this code instead:

function fixImages(){
ini_set('max_execution_time', 0);
$sql = "SELECT products_id as id, products_image as image FROM " . TABLE_PRODUCTS;
$query = tep_db_query($sql);
while($result = tep_db_fetch_array($query)){
	if ( !tep_not_null($result['image']) || !file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $result['image']) ){
		$updatesql = "UPDATE " . TABLE_PRODUCTS . " SET products_status = '0' WHERE products_id = '".(int)$result['id']."'";
		$updatequery = tep_db_query($updatesql);
		tep_db_free_result($updatequery);
	}
}
tep_db_free_result($query);
} # end function

Posted

you are a god! maybe zip this submit as contrib some people might find this useful, you can make other use for this other than disabling product if no image, for stores with thousands of items like mine this means alot.

 

it shows this warning at the bottom of easypopulate.php

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/alfi/public_html/admin/includes/functions/database.php on line 119

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/alfi/public_html/admin/includes/functions/database.php on line 119

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/alfi/public_html/admin/includes/functions/database.php on line 119

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/alfi/public_html/admin/includes/functions/database.php on line 119

 

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/alfi/public_html/admin/includes/functions/database.php on line 119

 

 

but it works! so all good! thank you!

Posted

Use this this function to get rid of that error message:

function fixImages(){
ini_set('max_execution_time', 0);
$sql = "SELECT products_id as id, products_image as image FROM " . TABLE_PRODUCTS;
$query = tep_db_query($sql);
while($result = tep_db_fetch_array($query)){
	if ( !tep_not_null($result['image']) || !file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . $result['image']) ){
		$updatesql = "UPDATE " . TABLE_PRODUCTS . " SET products_status = '0' WHERE products_id = '".(int)$result['id']."'";
		$updatequery = tep_db_query($updatesql);
	}
}
tep_db_free_result($query);
} # end function

Basically, since the query is simply an insert it does not need to be freed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...