Https and path for image/file from custom field

  • Posts: 5
  • Thank you received: 0
4 years 9 months ago #307125

-- HikaShop version -- : 4.0.3
-- Joomla version -- : 3.9.5
-- PHP version -- : 7.2.17

HI
I've got t the path of image stored in custom fields following this code

<?php $fieldsClass = hikashop_get('class.field');
$fields = $fieldsClass->getFields('frontcomp', $this->row, 'category', 'checkout&task=state');
foreach($fields as $key => $val){
 echo $fieldsClass->show($val,$this->row->$key); 
} ?>

I put the value inside img src tag and it works correctly

but when i turn my website from http to https randomly the images are not displayed correctly

How can I manage this problem?

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
4 years 9 months ago #307128

Hi,

we'll need more information on your issue to be able to help.
Please provide a link to a page with the problem and/or instructions to be able to reproduce the problem.

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
4 years 9 months ago #307157

Hi,

I see that your page is highly customized.
I see that in https, some of the images that are normally (by normally, I mean in http) displayed with the custom field, get your default image instead.
There is no system in the custom fields to display a default image instead of the one uploaded. And there is no such mechanism in the code you posted in your first message.
This indicates that there is something else you're not telling us which does that, and I'm feeling that it's probably there that the problem lies.

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 0
4 years 9 months ago #307200

Hi Nicolas
I try to explain my code
We have categories and subcategories.
As you can see in attachment this is how i set the menu item Products
The layout in the frontend is a customized version of listing and listing_img_description

The parent category has a custom field named 'fotoprodottosecondario' and i get it as follows

$fieldsClass = hikashop_get('class.field');
$fields = $fieldsClass->getFields('frontcomp', $this->row, 'category');



foreach ($fields as $fieldName => $oneExtraField) {
    if ($oneExtraField->field_namekey == 'fotoprodottosecondario'):
//echo $fieldsClass->show($val,$this->row->$key);
        $tags = $fieldsClass->show($oneExtraField, $this->row->$fieldName);
        preg_match('@src="([^"]+)"@', $tags, $match);
        $src = array_pop($match);
        $fotoprodotto = substr($src, 0, strpos($src, '/thumbnail_x'));
    endif;
}

and I put the result in
 <img src="<?php echo $fotoprodotto; ?> " onerror="this.onerror=null;this.src='<?php echo $default ?>';"  alt="<?php echo $this->row->category_name; ?>" class="product-image">

First question: How can I get the full image without using function substr ?

Then for every child categories I have to get again its image in custom field 'fotoprodottosecondario' in this way
$fields2 = $fieldsClass->getFields('frontcomp', $child, 'category');
foreach ($fields2 as $childFieldName => $childOneExtraField) {

    if ($childOneExtraField->field_namekey == 'fotoprodottosecondario'):
        $tags = $fieldsClass->show($childOneExtraField, $child->$childFieldName);
        preg_match('@src="([^"]+)"@', $tags, $match);
        $src = array_pop($match);
        $fotogrid = $src;
    endif;
}

and I put it here
 <img src="<?php echo $fotogrid; ?>" onerror="this.onerror=null;this.src='<?php echo $default ?>';"   alt="Product image" class="product-image">        
Any further suggestions?
Thanks in advance

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
4 years 9 months ago #307202

Hi,

Thanks, that's much more clear.
So if I look at your page with the javascript turned off, I don't have the images replaced and I see that some of the images can't be loaded. And if I look at the network tab of my browser's developer tools, I can see these images returning with a 500 HTTP error. And if I look at the returned response for them, I can see the error "Could not connect to MySQL server.":
monosnap.com/file/XP9qGU5qhxa2ZmwBCVNgpQtnVDYbSc
So it looks like the issue is that too many HTTP requests come at the same time, flooding the MySQL server with MySQL queries to initialize the page and load the data from the database to be able to output the images.
So, you would have to seek advice with your hosting provider:
www.percona.com/blog/2013/11/28/mysql-er...oo-many-connections/
However, I would actually recommend to do that customization differently. It would be much better to only have an input field where you would enter the name of the image and upload the images via the Joomla media manager.
Then, you could directly append the $this->row->fotoprodottosecondario to the URL of the media folder.
That way, the browser would directly load the image through apache, without using PHP nor MySQL.
The pages would display much faster, and it would be a lot more soft on the server side.

Finally, if you still want to keep the uploader in your custom field, and supposing that you don't sell files, you could change the "upload secure folder" setting of the HikaShop configuration to be in another folder, which would be accessible. That way, you could similarily directly append the $this->row->fotoprodottosecondario to the URL of that folder. You would get the best of both world.

The following user(s) said Thank You: giuliocrealia

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 0
4 years 9 months ago #307234

Thanks Nicolas for your quick response
I will not sell any files for this website. These are files that describe the product as you advice so I want change the upload safe folder settings.
My question is: how can I upload product image inside hikashop custom fields in an unsafe folder so that i can directly append the image path file in img tag?

Please Log in or Create an account to join the conversation.

  • Posts: 81379
  • Thank you received: 13037
  • MODERATOR
4 years 9 months ago #307237

Hi,

If you change the upload safe folder (for example to be the same as the upload folder), then when you upload the images via the custom product fields, they will end up in that upload folder. So for example, the default folder is images/com_hikashop/upload/
So in that case, you'll be able to do something like that:

<img src="http://mywebsite.com/media/com_hikashop/upload/<?php echo $this->row->fotoprodottosecondario; ?>" />

The following user(s) said Thank You: giuliocrealia

Please Log in or Create an account to join the conversation.

Time to create page: 0.068 seconds
Powered by Kunena Forum