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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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";
      }
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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")){

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.