I don't see attached files

LiteCart Fan
จาก Poland
เป็นสมาชิกตั้งแต่ ต.ค. 2023

Great addon. This could be the solution to my problem with the color sample of each product.

However, I don't see any section with files on the page. Is there anything else I need to do besides uploading the files and a piece of code?

Here is link to product with pdf file
https://mybudio.eu/en/interior-decorations-c-22/decorative-effects-for-the-wall-c-3/rust-effect-klondike-corten-valpaint-set-p-76

In attachment is proof

tim
Founder
จาก Sweden
เป็นสมาชิกตั้งแต่ พ.ค. 2013
tim

Do you run a different template name? If so, you would need to adjust the template part in the mod to match your template.

LiteCart Fan
จาก Poland
เป็นสมาชิกตั้งแต่ ต.ค. 2023

Now I see. 
Dodo did a few things for me and changed the template name. I didn't know about it until now
Thank you for your help. Now it is working

But one more question.
I would like the file to immediately open in the same window. How to do it?

The files added to products are catalogs with color samples

tim
Founder
จาก Sweden
เป็นสมาชิกตั้งแต่ พ.ค. 2013
tim

For the same window remove the attribute target="_blank" from the anchor tag.

LiteCart Fan
จาก Poland
เป็นสมาชิกตั้งแต่ ต.ค. 2023

It works great with Safari but nothing changes when I use PC and mobile Chrom

I thought that in my case it would be great if the file was just displayed without downloading.
THIS leads to a change in the code. Could you take a look from an expert and tell me if there will be any problems if I use it?


  require_once('includes/app_header.inc.php');

  try {

    if (empty($_GET['product_id'])) throw new Exception('Invalid product_id');
    if (empty($_GET['file_id'])) throw new Exception('Invalid file_id');

    $file_query = database::query(
      "select * from ". DB_TABLE_PREFIX ."products_files
      where product_id = ". (int)$_GET['product_id'] ."
      and id = ". (int)$_GET['file_id'] ."
      limit 1;"
    );

    if (!$file = database::fetch($file_query)) throw new Exception('Could not find a reference for the given file_id', 400);

    $src = FS_DIR_STORAGE . 'data/files/' . $file['file'];

    if (!is_file($src)) {
      trigger_error('Missing attachment '. $file['file'] . ' for product ' . $file['product_id'], E_USER_WARNING);
      throw new Exception('Found a reference for the file but it does not exist on the disk', 404);
    }

    header('Content-Type: ' . $file['mime']);
    header('Content-Disposition: inline; filename="' . $file['filename'] .'"');
    header('Content-Length: ' . filesize($src));

    $fh = fopen($src, 'rb');
    while ($buffer = fread($fh, 1024)) echo $buffer;
    fclose($fh);

    exit;

  } catch (Exception $e) {
    http_response_code($e->getCode());
    notices::add('errors', $e->getMessage());
  }
?>```
tim
Founder
จาก Sweden
เป็นสมาชิกตั้งแต่ พ.ค. 2013
tim

To display without downloading you have to edit the get_file.inc.php script and set the right mime type in the HTTP header for Content-Type and set content disposition to "inline".
You asked 😉

If the mime type is not supported by the browser it will fallback to downloading.

LiteCart Fan
จาก Poland
เป็นสมาชิกตั้งแต่ ต.ค. 2023

Screw it. Better is the enemy of Good - as we say in Poland.

I'm leaving it as the creator intended it.

Thx for help Tim

คุณ
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.