开发者

Script to Download File from Android Browser

开发者 https://www.devze.com 2023-02-21 10:09 出处:网络
I am not a web developer by all means. But I am trying to help someone deliver a video from their server. Basically when the user clicks a button on the website, we want the user to be prompted to dow

I am not a web developer by all means. But I am trying to help someone deliver a video from their server. Basically when the user clicks a button on the website, we want the user to be prompted to download the video. So after Googling for a while I figured out how to write a short php script using content-disposition:

<?php
$fn = 'videoFile.mp4';

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Description: File Transfer');
header('Content-type: video/mp4');
header('Content-Length: '.filesize($fn));
header('Content-disposition: attachment; filename='.$fn);
readfile($fn);
?>

So the button on the website points to this script. PC browsers seem to start the download with no problem. But the main focus of this is for Android phones. When you click to download the file on the default Android Browser, it fails and all it says is "Download Unsuccessful".

Another thing is that on my computer (using Firefox), the download starts and at about 200MB, it just stops. It doesn't show any signs of failure, it just looks like it finished downloading. The actual file size is about 1GB.

I have played around with the content-type quite a bit, hoping that was the problem. I used "video/mpe开发者_StackOverflowg" and "application/force-download" and neither of them worked.

Is there something I'm not doing write? Could the 2 problems be related? Should I be going about this a different way? Thanks for any input.


The Android browser does not appear to like Content-disposition: and related headers. I recommend just a plain redirect to the file in question.

0

精彩评论

暂无评论...
验证码 换一张
取 消