Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Using images both local and remote images in OSC Bootstrap


rogerwhitfield

Recommended Posts

A few years ago I managed to get both remote and local images to work at once, I posted the information on this forum in case anyone else found it useful. Now I have upgraded to OSC 2.3.4 Bootstrap I have found some small differences that need to be addresses to make the modification work, these are as follows:-

 

The images are displayed using a routine in includes/functions/html_output.php, to enable remote images you need to make the following modifications:

 

I located this function on line 73:-

 

////
// The HTML image wrapper function
  function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '', $responsive = true, $bootstrap_css = '') {
    if ( (empty($src) || ($src == 'images/')) && (IMAGE_REQUIRED == 'false') ) {
      return false;
    }

 

and then added the following directly after it:-

 

 // check to see if image is external or internal (check for http) and modify $src
 
 // check to see if image is external or internal (check for http:) and modify $src added by RW 12-09-2016 to support remote images
 $mystring = $src;
    if ( substr($mystring, strlen(DIR_WS_IMAGES), 4) == 'http') {
        // use remote file
  $src = substr($mystring,(strlen(DIR_WS_IMAGES)));
       } else {
     if (file_exists($src)) {
       // use local file
   } else {
       // Use no image file
         $src = DIR_WS_IMAGES . 'no_img.jpg';
       }
 }

 

Basically this looks at the image source variable $src and checks to see if the first thing after the image path is html, if it is then it is a remote image and the local image path is removed from the variable $src so that the image can be found online, if it is a local image then it is displayed as usual. Finally I added the last bit so that if the image is missing then it displays the no_img.jpg (you will need to make sure you have a file in images with this name.

 

Now this worked fine on OSC 2.3.3 but on the newer version it wouldn't work, the reason was because I was using DIR_WS_IMAGES to point to the images folder, however this is not defined so you need to edit includes/configure.php and add the line:-

 

  define ('DIR_WS_IMAGES', 'images/');

 

assuming that your local images are stored in the images folder, if they are stored elsewhere then just change the path to match the location.

 

I have done this because I have a variety of products from different suppliers, some products are entered manually and we have local images for them and others are supplied via an automatic feed that supplies a url to the image. This modification allows me to just dump the url into the image field and display the image correctly.

 

If anyone else has the same requirement then please feel free to use, or to improve this code. I have attached the complete working html_output.php file.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...