PHP mp3下载脚本在Android手机上不起作用

时间:2015-08-02 12:44:56

标签: php android

我有一个PHP脚本,用于从我的网站上提供服务器mp3文件。它适用于桌面浏览器,但无法在Android浏览器上运行。当我尝试从我的网站下载mp3文件时,我不断在Android手机上收到“下载不成功”错误。 这是代码:

session_start();
$post_id = $_SESSION['post_id'];

$_SESSION['post_id'] = '';

require($_SERVER["DOCUMENT_ROOT"] . "/wp-blog-header.php" );



function set_download_count($postID) {
    $count_key = 'custom_download_count';
    $dcount = get_post_meta($postID, $count_key, true);
    if($dcount==''){
        $dcount = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $dcount++;
        update_post_meta($postID, $count_key, $dcount);
    }
}

$count = $_GET['count'];
//$post_id = $_GET['p'];
$count++;

$file = $_GET['file']; 

//$output = array_shift(explode('&', $file));

if($count == 1) {
    //echo "1";
    set_download_count($post_id);

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file)."");
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));

readfile($file);
exit;


}else {
     echo "0";
    exit();
}

有谁知道造成这种情况的原因以及如何解决这个问题?感谢。

0 个答案:

没有答案