2014-02-18 5 views
0

я сделал с загрузкой в ​​ПК устройстве с ниже кодомСкачать файл в мобильном устройстве

$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). Как заставить мобильные устройства загружать файл?

+0

Почему вы настройки типа контента и расположение несколько раз? – ElefantPhace

+0

@ElefantPhace Я просто редактирую – freestyle

ответ

2

Это все, что вам нужно:

$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 
Смежные вопросы