PHP Stream Script Works for Flash Apps, But Not iPhone Mobile Browsing

I have a php script that grabs a file and sends it on it’s way (I use the script to prevent longterm hotlinking). It works great for downloading and streaming videos to flash applications. Problem is that I can’t get the videos to play through to iphone (or other apple devices) when used. Here are the headers I’m using:

header("Pragma: public");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
header("Cache-Control: must-revalidate, post-check=3600, pre-check=18600");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: video/mp4");
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=\\"trailerdl.". $extension ."\\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($file_real));
// Send file for download
if ($stream = fopen($file_real, 'rb')){
while(!feof($stream) && connection_status() == 0){
//reset time limit for big files

I’ve tried disabling the content-disposition, but that didn’t help. Is there a way to get iPhone to work with a PHP script that sends the mobile-ready mp4 file on its way?

All feedback appreciated.


I’ve seen similar complains in the past, due to accept ranges. I’m no expert here so sorry I can’t be of more help, but check out

Thanks for the link! I fixed it, though I don’t know if it works in older apple iphone OS versions. But I’m assuming I’ll hear back quick.

Great :slight_smile: Care to share what the problem was for future reference for others?

Oh yeah,

The major issue are the headers: Content-Range and Accept-Ranges for mobile. They are extremely specific. The script on that page provided ensures that all possible outcomes are covered. I think you could get away with creating a simplified version of just doing the content-range and accept-ranges as shown in the example, without the giant function, but that leaves the script up to chance on whether it will work 100% of the time or not. So, in the end, I just used the entire thing.


Ah! I did find something about this PHP script that I now don’t like. While the videos now work flawlessly with Apple Mobile, Android has gone from streaming the videos directly (like it used to do), to forcing a file download instead.

Any trick to have PHP streaming script to allow Android to play directly and not download like an attached file?