People often don’t know how to save a file from a link. You send them a link and it seems just impossible to them to be able to right-click on it and choose “Save link as”. Especially on macs, where the concept of right-click didn’t really exist (and is still unknown to many – it seems). So, how do you help somebody who needs to download a big video file from your server bit it keeps openning in browser in some quicktime player or something. You force the browser to download. Create a PHP file that will send correct headers to browser:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php $file = 'videofilename.mov'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($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; } ?> |
Just take care there are no spaces outside of php tags.