I have an <a href> link on a page that points to a video file (mp4). When the visitor clicks the link, the video file opens in the browser window.
If you want to download the file, you have to “right click”, and then “save link as…”
I want that so that on a single click file will download (so that I don’t have to right click).
edit: What’s the problem here?
<?php
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename=file');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
?>
Set the
Content-Dispositionheader toattachment. For example: