Du skal være logget ind for at se siden×

I don't see attached files

LiteCart Fan
Tól től Poland
Tagság okt. 2023 óta

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
Tól től Sweden
Tagság máj. 2013 óta
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
Tól től Poland
Tagság okt. 2023 óta

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
Tól től Sweden
Tagság máj. 2013 óta
tim

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

LiteCart Fan
Tól től Poland
Tagság okt. 2023 óta

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
Tól től Sweden
Tagság máj. 2013 óta
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
Tól től Poland
Tagság okt. 2023 óta

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

Te
Ez a weboldal nem használ cookie-kat és nem használ harmadik féltől származó nyomkövetési technológiát. Úgy gondoljuk, hogy jobban tudjuk csinálni, mint mások, és tényleg gondolunk az Ön magánéletére.