1

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>
<IfVersion >= 2.4>
    Require all denied
</IfVersion>

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? – Rohan Hapani 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? – simonthesorcerer 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
0

Replace this line into your cms page :

<a href="{{media url=downloadable/zipfile.zip}}
">Download ZIP Here</a>
  • Didn't work. See update to my post. – Mingle Li Jul 19 '18 at 18:55
  • If in your anchor tag this url you get which mention in updated post then you need to change code. because base url need to download file properly. If base url + image path will be getting in anchor tag. Then , zip will be download. – Rohan Hapani Jul 19 '18 at 19:00
  • I'm sorry, I don't understand what you mean. However, I did find a workaround. – Mingle Li Jul 19 '18 at 19:06
  • /pub/media/downloadable/zipfile.zip your path like this. But , it should be like this. example.com/pub/media/downloadable/zipfile.zip. So, base url of magento required & that's why I told you to replace code. After replace , Clean cache if cache is enable – Rohan Hapani Jul 19 '18 at 19:09
  • Putting full base URL did not work. – Mingle Li Jul 19 '18 at 19:18
0

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.