ghurty Posted July 1, 2009 Share Posted July 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
abdfahim Posted July 1, 2009 Share Posted July 1, 2009 make use of the function file_exists Quote Link to comment Share on other sites More sharing options...
ghurty Posted July 1, 2009 Author Share Posted July 1, 2009 Can you point me to a guide that explain the use of that in simple to understand ways? Thanks Quote Link to comment Share on other sites More sharing options...
abdfahim Posted July 1, 2009 Share Posted July 1, 2009 check the link http://php.net/manual/en/function.file-exists.php Quote Link to comment Share on other sites More sharing options...
ghurty Posted July 1, 2009 Author Share Posted July 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
abdfahim Posted July 1, 2009 Share Posted July 1, 2009 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"; } } ?> Quote Link to comment Share on other sites More sharing options...
ghurty Posted July 1, 2009 Author Share Posted July 1, 2009 I forgot about using "!". Thanks a mil Quote Link to comment Share on other sites More sharing options...
ghurty Posted July 1, 2009 Author Share Posted July 1, 2009 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 Quote Link to comment Share on other sites More sharing options...
abdfahim Posted July 1, 2009 Share Posted July 1, 2009 see, you have to give absolute path (like "C:\apache\htdocs\logo\logo.jpg") or relative path (like "logo/logo.jpg" provided both your php file and the logo Folder resides on same folder) or use dot (../) to go up the directory. Quote Link to comment Share on other sites More sharing options...
ghurty Posted July 1, 2009 Author Share Posted July 1, 2009 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. Quote Link to comment Share on other sites More sharing options...
abdfahim Posted July 1, 2009 Share Posted July 1, 2009 I suggest, 1) print $GLOBALS['VendorLogo'] variable 2) then hardcode that thing to file_exists function and check whether file_exists working properly. Quote Link to comment Share on other sites More sharing options...
ghurty Posted July 1, 2009 Author Share Posted July 1, 2009 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")){ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.