How to add file size

  • Posts: 50
  • Thank you received: 2
6 years 1 month ago #303472

-- url of the page with the problem -- : localhost
-- HikaShop version -- : 4.0.1
-- Joomla version -- : 3.9
-- PHP version -- : 5.6

hi

I'm working on file shop and override template view for products page
I have added many elements like product_hit , Product_id , Vendor_name ,.... but I need the function to show file size, I can use function filesize($filename) but it needs file path to work and as I know they are in safe folder.

I know how to add it to product page but i don't know the way of getting file size that has been uploaded for the product?
How can I access file path to use filesize($filename) or another way to show file size for customer?

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

  • Posts: 83511
  • Thank you received: 13511
  • MODERATOR
6 years 1 month ago #303486

Hi,

The information of the files are stored in $this->element->files on the product page.
So you want to do something like that:

$file = reset($this->element->files); // that will give the information of the first file of the product in $file
$relative_file_path = $file->file_path; // that will give you the relative path of the file from the upload safe folder.
$absolute_fie_path = HIKASHOP_ROOT.'media/com_hikashop/upload/safe/'.$relative_file_path; // that will give you the absolute path
echo filesize($absolute_fie_path); // that will display the file size in bytes.

The following user(s) said Thank You: pma

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

Time to create page: 0.041 seconds
Powered by Kunena Forum