Reputation: 7785
I am facing the issue that we are linking a .mp4-File on a shared hosting system, but we'd like to have the link working as a download link. We're doing this with the download
attribute in the link:
<a href="https://another-hosting.org/video.mp4" download>
As other threads state, the download
attribute is ignored by chrome, firefox and safari due to the fact that the link points to another origin.
To avoid this, my approach would be to include the file via PHP (cURL / File Stream?) and then output it directly with the appropriate content type and content disposition. However, I have no idea how to import the file as a resource and then output it.
<a href="https://my-hosting.org/download-video.php?file=video.mp4" download>
Can anyone give me a hint which function set of PHP i should consider? Thanks!
Upvotes: 0
Views: 292
Reputation: 397
Try this in your download-video.php
maybe?
<?php
$vidFile=$_GET["file"];
$videoURL = "https://another-hosting.org/$vidFile";
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=video.mp4");
header("Content-Type: video/mp4");
readfile($videoURL);
Upvotes: 1