当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Download file in mobile device

问题描述:

I have done with download in pc device with below code

 $file_url_source = "C:/test.xlsx";

$file_url = "C:/test.xlsx";

header('Content-Type: text/json; charset=UTF-8;');

header('Content-Description: File Transfer');

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"';

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($file_url));

ob_clean();

flush();

readfile($file_url);

But it's not working for mobile device (I just tested it in Android mobile and it downloads the download.php file). How can I make mobile devices download the file?

网友答案:

This is all you need:

$file_url = "xxxxxx";
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="' . basename($file_url) .'"');
readfile($file_url);

Your problem is with this line

header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"';
#                                                                                  ^^^^^^^^^
#              this is where your problem is, you never put the last " around the file name
分享给朋友:
您可能感兴趣的文章:
随机阅读: