Jump to content

how to display product attachment filesize?


aaront1
 Share

Recommended Posts

Hi,

 

On the product page, is there a way to display the attachment filesize?

 

in other words, where can I get and add the filesize and set it to a variable, so that the product.tpl can display that value?

Share this post


Link to post
Share on other sites

Who said it isn't possible :rolleyes:

 

in your ProductController.php file, assign a new smarty variable to define prestashop download directory

$this->context->smarty->assign('download_dir' , _PS_DOWNLOAD_DIR_);

and then in your product.tpl file, modify the content of attachments block like this :

    {* NOTE: we assign a new smarty vars: $filePath(a path to file), $fileSize(attachment fileseze in Kb) *}
    {if isset($attachments) && $attachments}
        <ul id="idTab9" class="bullet">
        {foreach from=$attachments item=attachment}
            {assign var=filePath value=$download_dir|cat:$attachment.file}
            {assign var=fileSize value=($filePath|@filesize)/1024}
            <li><a href="{$link->getPageLink('attachment', true, NULL, "id_attachment={$attachment.id_attachment}")}">{$attachment.name|escape:'htmlall':'UTF-8'} <strong>({$fileSize|number_format:2:'.':','} {l s='Kb'})<strong></a><br />{$attachment.description|escape:'htmlall':'UTF-8'}</li>
        {/foreach}
        </ul>
    {/if}

 

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More