Download file instead of stream, is it possible?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Greetings,

Came across this issue if somebody knows the solution.

I am selling mp3 tracks from the store and have stored mp3 files on file system. I have saved url under downloadable product. When I click on "Download" link to download the file, Chrome & Firefox starts streaming/playing the file in the browser instead of offering save dialog. Because of this, the browser exposes the real download url instead of encrypted url. This can be a security threat as the link can be shared with anyone allowing someone to download the file without paying for it.

Screenshot1

Is there any way to block streaming of audio files in browser and offer file download/save dialog instead?

Thanks in advance.
11 years ago
Anyone please throw some light on this!
11 years ago
Yes, this is a problem.  Most DB's aren't large enough to store enough content so you are almost forced to use download URL's.  But, then, the browser just wants to "play" the file (plus ACTUAL download URL ends up in the browser when it plays!)... I can't find any solution to this other than renaming the file to "zip" or something that forces it to download but that isn't a solution since users would then be required to FIX it after it downloads!
11 years ago
AHA!  I have figured out a work around that won't play the "mp3" file (or whatever other type of file you want to prevent from coming up in a browser) and thereby show the user the URL of the source file in the browser.

Follow these steps:

1) Create a folder to hold your content (mp3 files, etc).
2) FTP your files to that new location.

3) Now, create a simple PHP file (with any text editor) with the following lines of code and save as "sendfile.php":

<?php
   $file = $_GET['file'];
   header ("Content-type: octet/stream");
   header ("Content-disposition: attachment; filename=".$file.";");
   header("Content-Length: ".filesize($file));
   readfile($file);
   exit;
?>

4) Upload "sendfile.php" to wherever your content is.
5) Now, when you enter the downloadable product URL, just use "http://path-to-your-store/path-to-your-content/sendfile.php?file=yourfile.mp3"

What I do is name my files using my SKU as the filename and "mp3" as the extension.  So, it's easy just to copy & paste your SKU into the "yourfile" above and add the ".mp3" extension.  

6) Repeat step 5 for every product/product variant you need to do this for.

Hope this helps!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.