I have a ZIP file. I want it so when a user clicks a link on a page, it will download the ZIP file.

I have the ZIP under pub/media/downloadable and inside there's a .htaccess file, and currently this is the content inside:

<IfVersion < 2.4>
    order allow,deny
    deny from all
<IfVersion >= 2.4>
    Require all denied

AddType application/octet-stream .zip

And the link on my page is this:

<a href="/pub/media/downloadable/zipfile.zip">Download ZIP Here</a>

But clicking on the link simply redirects to /pub/media/downloadable/zipfile.zip instead of downloading, which brings a 404.

== UPDATE ==

To make the link downloadable, all I had to do was add the download attribute to the <a>, like this:

<a href="/pub/media/downloadable/zipfile.zip" download >Download ZIP Here</a>

However, when I tried to download it, Google Chrome said "Failed - No File". The path is correct and the file is there, with permissions 644.

  • Can you please upload the file code where this link available? Jul 19 '18 at 16:57
  • Where you added link (phtml/cms page) ?
    – Pawan
    Jul 19 '18 at 16:59
  • Is your shop running in a subdirectory? Jul 19 '18 at 17:26
  • @RohanHapani I have this link in a CMS page.
    – Mingle Li
    Jul 19 '18 at 18:34
  • @Pawan See above comment.
    – Mingle Li
    Jul 19 '18 at 18:34

I don't have a proper solution or an explanation why this works, but all I did was move the ZIP file to pub/media directory and it worked. The lines in the .htaccess file did not do anything.

All that's needed is the download attribute on the anchor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.