2012-12-14 2 views
3

APK 파일 다운로드를 위해 카운터를 늘린 다음이 파일을 브라우저로 다운로드하여 다운로드합니다.apk 파일을 강제로 다운로드하기위한 헤더

여기에 내가 가진 무엇 :

<?php 
    $file = "android.apk"; 

    function force_download($file){ 
    header("Pragma: public", true); 
    header("Expires: 0"); // set expiration time 
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    header("Content-Type: application/force-download"); 
    header("Content-Type: application/octet-stream"); 
    header("Content-Type: application/download"); 
    header("Content-Disposition: attachment; filename=".basename($file)); 
    header("Content-Transfer-Encoding: binary"); 
    header("Content-Length: ".filesize($file)); 
    die(file_get_contents($file)); 
    } 

    force_download($file 

문제는 파이어 폭스와 같은 브라우저, 그것은 다운로드 것을이지만 같다 'android.apk - 0 바이트'. 기본적으로 파일 내용을 다운로드하지 않습니다.

내가 뭘 잘못하고 있니? 이것에 대한 해결책?

중요 : 모바일에서 작동해야합니다.

);

+0

file_get_contents ($ file)가 파일을 읽을 수 있는지 확인하고, 헤더없이 테스트하십시오. – RezaSh

답변

0

스크립트가 서버에서 .apk MIME 유형이 기본이 아니며 따라서 초보자가 설정하기 어려운 서버로 이동할 경우 복잡한 헤더 정보를 사용할 필요가 없다는 것을 깨달았습니다. .

간단한 리디렉션 할 것입니다 :

$file_name = $_GET['f']; //$_GET['f'] has the link to the file like http://mydomain.com/file/android.apk 


//Do database query or increase download counter 

header('location: '.$file_name); 

짜잔를! 카운터를 늘리면 다운로드가 브라우저로 푸시됩니다.

0

강제로 다운로드하지 않는 .apk 링크에 액세스 한 적이 결코 없으므로 강제 다운로드가 필요한지 확실하지 않습니다. 카운터를 증가시키는 한, 카운터가 완료된 후 apk 파일로 전달하는 페이지로 연결하는 것일뿐입니다.

를 들어 인스턴스 링크 사람에게 : getapk.php apkid = 1

그런 getapk.php에 이런 일을 수행합니다?, 많은 세부 사항을 나뭇잎 물론

$update = mysql_query("UPDATE apps SET downloads..."); 
if ($update) { header("Location: appname.apk"); } 

을하지만 경우 당신은 다른 어떤 도움이 필요합니다. 나는 더 자세한 내용을 기꺼이 제공 할 것입니다.

관련 문제