Helllo there..
The following code simply reads out myfile.mp4
and serves it to the client:
$path = "myfile.mp4";
header('Content-Description: File Transfer');
header('Content-Type: ' . mime_content_type($path));
header('Content-Disposition: inline; filename="'.basename($path).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
readfile($path);
exit;
Sadly, with files over 3GB (from what I observed), mp4 files are really hard to read.
Here is the list of problems:
1) You cant seek to the end of the video. readfile()
will only serve your files "linearly" i'd say...
2) It takes an awful amount of time to load compared to direct, vanilla file access.
I tried looking into both the vanilla file access headers and mines and this is what I got:
== Vanilla apache2 file serving ==
Cause: Document
HTTP/1.1 200 OK
Date: Fri, 13 Dec 2019 05:55:42 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Thu, 12 Dec 2019 18:51:19 GMT
ETag: "9800d27f-599863b11b568"
Accept-Ranges: bytes
Content-Length: 2550190719
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: video/mp4
Cause: Media
HTTP/1.1 206 Partial Content
Date: Fri, 13 Dec 2019 05:58:29 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Thu, 12 Dec 2019 18:51:19 GMT
ETag: "9800d27f-599863b11b568"
Accept-Ranges: bytes
Content-Length: 9032319
Content-Range: bytes 2541158400-2550190718/2550190719
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: video/mp4
And here's my php script's headers (It took me 4 minutes to get them!!!)
Cause: Document
HTTP/1.1 200 OK
Date: Fri, 13 Dec 2019 05:57:36 GMT
Server: Apache/2.4.29 (Ubuntu)
Content-Description: File Transfer
Content-Disposition: inline; filename=" - 20191126(ç«) 2330éå§ - ãã³ãã³çæ¾é.mp4"
Expires: 0
Cache-Control: must-revalidate
Pragma: public
Content-Length: 2550190719
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: video/mp4
I also have a "Cause: media" request apparently on this page but I didnt receive any headers from the server..
What am I doing wrong? Is there a better function to do this? Preferably a function that also let me transfer JPEG files and stuff like that...
Thanks for the read everyone!!