【问题标题】:Download file in mobile device在移动设备中下载文件
【发布时间】:2014-02-18 03:15:22
【问题描述】:

我已经用下面的代码在电脑设备上下载了

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

但它不适用于移动设备(我刚刚在 Android 移动设备上对其进行了测试,它会下载 download.php 文件)。如何让移动设备下载文件?

【问题讨论】:

  • 为什么要多次设置内容类型和配置?
  • @ElefantPhace 我只是编辑

标签: php jquery-mobile mobile


【解决方案1】:

这就是你所需要的:

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

你的问题在于这一行

header('Content-Disposition: attachment; filename="' . basename($file_url_source)."") . '"';
#                                                                                  ^^^^^^^^^
#              this is where your problem is, you never put the last " around the file name

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多