I'm looking to add a "Download this File" function below every video on one of my sites. I need to force the user to download the file, instead of just linking to it, since that begins playing a file in the browser sometimes. The problem is, the video files are stored on a separate server.
Any way I can force the download in PHP?
Tested download.php file is
and the link to download is
Try this:
The key is the
header()
. You need to send the header along with the download and it will force the "Save File" dialog in the user's browser.using this code. is it possible to save the file name to what you want. for example you have url: http://remoteserver.com/file.mp3 instead of "file.mp3" can you use this script to download the file as "newname.mp3"
You could try something like this:
I just tested it and it works for me.
Please note that for
readfile
to be able to read a remote url, you need to have yourfopen_wrappers
enabled.