Jump to content

How: If file not found, assgin different file instead?


ghurty

Recommended Posts

I have the following code to pull up a "vendor" logo:

 

while($vendor = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
		$GLOBALS['VendorId'] = $vendor['vendorid'];
		$GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/". $vendor['vendorid'] ."_logo.png";

 

Any suggestions how I can make it that if it does not find a file with that name, it will assign a different file to that variable instead?

 

 

Thanks

So should this code work:

	while($vendor = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
		$GLOBALS['VendorId'] = $vendor['vendorid'];
		$GLOBALS['VendorLogotemp'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/". $vendor['vendorid'] ."_logo.png";
		if(file_exists( $GLOBALS['VendorLogotemp'] )){
			$GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/". $vendor['vendorid'] ."_logo.png";
			} else {
				$GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/"."defaultlogo.png";
				}

 

 

Thanks

yup, though u r putting some extra line, u can do it like below

<?php
while($vendor = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
      $GLOBALS['VendorId'] = $vendor['vendorid'];
      $GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/". $vendor['vendorid'] ."_logo.png";
      if(!file_exists( $GLOBALS['VendorLogo'] )){
            $GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/"."defaultlogo.png";
      }
}
?>

I tried

		$GLOBALS['VendorId'] = $vendor['vendorid'];
		$GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/". $vendor['vendorid'] ."_logo.png";
          if(!file_exists( $GLOBALS['VendorLogo'] )){
            $GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/"."defaultlogo.png";
      }

 

And no matter what, it goes to the defaultlogo. However if I comment out the whole  if !file_exists part, it displays the real logo. For some reason when checking, it considers the logos not found.

 

 

Thanks

But what gets me confused is that how come when I just have:

	
$GLOBALS['VendorId'] = $vendor['vendorid'];
$GLOBALS['VendorLogo'] = GetConfig('ShopPath').'/'.GetConfig('ImageDirectory').'/'."vendor_images/". $vendor['vendorid'] ."_logo.png";

 

It does pull up and display the logo properly.

 

The php file and images are in two different directories.

Very interesting.

In order for the if filexists to work, I had to code in the exact path. the following example DID work. THank you for all the help.

 if(!file_exists( '/homepages/2/d3452/htdocs/test'.'/'.GetConfig('ImageDirectory').'/'."vendor_images/". $vendor['vendorid'] ."_logo.png")){

Archived

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

×
×
  • 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.