Prestashop. Forbidden when trying to download a file

0

I'm developing a module to upload files to the downloads folder of Prestashop and even there all right.

The problem is when trying to download any of these files, which gives me the following error:

Forbidden You do not have permission to access this document.

This is the link I'm using:

<a href="/download/{$csv['name_file']}_{$csv['name_csv']}" class="btn btn-default">Descargar</a>

I hope someone can enlighten me!

    
asked by Jose Francisco Dominguez Palac 25.09.2017 в 17:49
source

1 answer

0

I have already found a functional alternative. I modified the link by a small form:

<form action="{$link->getModuleLink('jmarketplace', 'sellercsvlist', ['csv_name' => $csv['name_file']], true)|escape:'html':'UTF-8'}" method="post" class="std">
      <input type="submit" id="download_csv" name="download_csv" value="{l s='Download' mod='jmarketplace'}" class="btn btn-default btn-sm">
</form>

And in the controller within the postProcess () the corresponding action:

if (Tools::isSubmit('download_csv')) {
        $csv = Tools::getValue('csv_name');

        $csv = SellerCSV::getCSVByName($csv);
        $csv_name = $csv['name_file'] . '_' . $csv['name_csv'];

        $file = _PS_DOWNLOAD_DIR_ . $csv_name;
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename='.basename($file));
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        ob_clean();
        flush();
        readfile($file);
        exit;
    }

With this the desired file is downloaded correctly. I hope this works for someone else!

    
answered by 26.09.2017 / 13:10
source