CodeIgniter Forums

Full Version: How force download mp4 file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I have 10 video files with mp4 format
I download this files from my php script
My code is :
PHP Code:
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($filename).'?id='.time());
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' filesize($filename));
readfile($filename); 

But speed is low when user try to download
and when i use redirect(base_url().$filename); speed is good and user can watch video speedly

M goal from this way is user cannnot download video and have to watch it with my php script file

Thanks
@omid_student,

There is a lot of things to trouble shoot. What kind of connection does your user have? Are there any download limitations from your hosting company? How big are the videos?
Here are a few different ways of doing it:

Force download MP4 file – PHP or .htaccess
(09-02-2019, 08:09 AM)php_rocs Wrote: [ -> ]@omid_student,

There is a lot of things to trouble shoot.  What kind of connection does your user have?  Are there any download limitations from your hosting company?  How big are the videos?
Thanks
Files are about 20 mb
My users are two user now
When i redirect to video,speed is good

(09-02-2019, 09:00 AM)InsiteFX Wrote: [ -> ]Here are a few different ways of doing it:

Force download MP4 file – PHP or .htaccess
Thank you
Do you can say why speed is low when i try send mp4 to header?
No idea why it would be slow using the header, the users internet speed could slow it down.
(09-02-2019, 11:58 AM)InsiteFX Wrote: [ -> ]No idea why it would be slow using the header, the users internet speed could slow it down.
Internet speed is very good
you could try doing an ob_clean(); first and see if that helps.
(09-02-2019, 04:30 PM)InsiteFX Wrote: [ -> ]you could try doing an ob_clean(); first and see if that helps.
i tried it already my friend
Try running the CI Profiler and check your log files in CI and on the server.
(09-03-2019, 02:45 AM)InsiteFX Wrote: [ -> ]Try running the CI Profiler and check your log files in CI and on the server.
Ok Thanks