Post by klaviyojad » Thu Oct 08, 2020 10:19 am

Hi I am working in the catalog/product controller and wish to construct the image url of the product because I wanted to pass it via AJAX javascript code on the page.

Right now the best way I am coming up with it is using this code:

Code: Select all

$data['image'] = "http://".$_SERVER[HTTP_HOST]."/image/".$product_info['image'];
Was wondering if there was a better way? ie not having to specify the protocol or concat strings

Newbie

Posts

Joined
Fri Aug 07, 2020 1:58 am

Post by IP_CAM » Thu Oct 08, 2020 10:58 am

If you plan to use 'cookiefree' Images, to please the Test Sites,
you should use the 'opposite' Linking. I.E., if your Site runs under
http(s):// www. yoursite. com/image/ ....
your images should be linked has
http(s):// yoursite. com/image/ ....
or then in reverse. Page Loading is then more effective.
Most easy to be set in the config.php File(s), like:

Code: Select all

// HTTP
define('HTTP_SERVER', 'http://www.bigmax.ch/shop/');
define('HTTP_IMAGE', 'http://bigmax.ch/shop/image/');

// HTTPS
define('HTTPS_SERVER', 'http://www.bigmax.ch/shop/');
define('HTTPS_IMAGE', 'http://bigmax.ch/shop/image/');
Ernie

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by letxobnav » Thu Oct 08, 2020 1:09 pm

cookie-free images, i.e. cookieless domains become absolutely useless when you start using http/2.

That aside, that controller already creates the absolute url for the resized product image:

Code: Select all

			$this->load->model('tool/image');

			if ($product_info['image']) {
				$data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_popup_height'));
			} else {
				$data['popup'] = '';
			}

Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces

“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by paulfeakins » Thu Oct 08, 2020 5:50 pm

klaviyojad wrote:
Thu Oct 08, 2020 10:19 am
Hi I am working in the catalog/product controller and wish to construct the image url of the product because I wanted to pass it via AJAX javascript code on the page.
Why would that mean it needs to be absolute?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by klaviyojad » Sat Oct 10, 2020 3:12 am

I do know that the controller already creates the absolute url for the resized product image. I do not wish to use the results of that since it pulls a cached directory like [hostname]/image/cache/catalog/demo/canon_eos_5d_1-500x500.jpg I would rather a URL like: [hostname]/image/catalog/demo/canon_eos_5d_1.jpg

Newbie

Posts

Joined
Fri Aug 07, 2020 1:58 am

Post by sw!tch » Sat Oct 10, 2020 5:01 am

As opposed to http://".$_SERVER[HTTP_HOST].

You could use $this->config->get('config_url') or $this->config->get('config_ssl')

If its something you will reuse multiple times, then you could create a private helper method in your class to construct the url and just pass the filename.

You could even do a new method in the URL class if you wanted something more global.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Who is online

Users browsing this forum: No registered users and 93 guests