Jump to content

[SOLVED] check if file_exists - manufacturer's logo


Jaguaro

Recommended Posts

Good afternoon,

I've inserted two lines of code on the manufacturer.tpl file, to display the logo on the manuf.'s page.

 

I would like to error check it, because I have a few manufacturers without logo.

Here is my code:

{assign var="myfile" value="{$base_dir}img/m/{$manufacturer->id}.jpg"}
<img src="{$base_dir}img/m/{$manufacturer->id}.jpg" /> <br/>

I would like to display it only if  the file exists.

 

I tried this, but it doesn't work:

{assign var="myfile" value="{$base_dir}img/m/{$manufacturer->id}.jpg"}
<if file_exist($myfile)>
<img src="{$base_dir}img/m/{$manufacturer->id}.jpg" /> <br/>
</if>

How can I fix it?

 

Thanks,

C

Link to comment
Share on other sites

Thank you Vekia,
Anyway I wrote the wrong code up here, I know that it requires brackets.
 
After long troubleshooting I understood that my server ( Aruba ) doesn't accept the absolute path for the file_exists function. The code below works because it's with relative path.
{assign var="myfile" value="img/m/{$manufacturer->id}.jpg"}
{if file_exists($myfile)} 
<img src="{$base_dir}img/m/{$manufacturer->id}-large_default.jpg" /> <br/>
{/if}
 

Thanks!

Edited by Jaguaro (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 4 years later...

Hi,

Sorry for the late response. But for other members with the same problem, using a relative path is not a good idea.

$base_dir is not the full path but the path on your URL. You need to use _PS_IMG_DIR_.

Assign the variable on your module / controller

 514         $this->smarty->smarty->assign(
 515             'rm_img_dir',
 516             _PS_IMG_DIR_
 517         ); 

On your template, create the var with the fullpath

{assign var="icon_full_path" value="{$rm_img_dir}rm/c{$subcategory->id}.png"}

And use it on your template :

{if file_exists($icon_full_path)}...{/if}

 

Best regards,

Edited by Maxence de Flotte (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...