2017-04-13 7 views
0
public function download_file($link='https://apkpure.co/apk/com.ezfun.p1767.dns_gp1/00b97d3d32a4f8e6cbecff7da5a4af41/1.0/0dfa1365e8e1c70bf2dcf391350a7a77/', $filename='com.ezfun.p1767.dns_gp1_1.0'){ 

    $extension = 'apk'; 

    $mime = 'application/octet-stream'; 

    if(strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) { 
     header('Content-Type: "'.$mime.'"'); 
     header('Content-Disposition: attachment; filename='.$filename.'.'.$extension); 
     header('Expires: 0'); 
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
     header("Content-Transfer-Encoding: binary"); 
     header('Pragma: public'); 
    } else { 
     header("Pragma: public"); 
     header("Expires: 0"); 
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
     header("Cache-Control: private", false); 
     header("Content-Type: ".$mime, true, 200); 
     header('Content-Disposition: attachment; filename='.$filename.'.'.$extension); 
     header("Content-Transfer-Encoding: binary"); 
    } 

    readfile($link); 

} 

私はreadfileがapkファイルをダウンロードする必要がありますが、私はこのウェブサイトを直接訪問することはできません、私はプロキシが必要です。readfile()はプロキシの後ろにありますか?

どのような提案ですか?

答えて

0

使用このコードはカールを使用してプロキシでファイルをダウンロードします

function download_file($url, $filename) { 

    $proxy = 'Proxy IP ADDRess'; //128.114.63.15:3128 
    $handle = curl_init(); 
    curl_setopt($handle, CURLOPT_URL, $url); 
    curl_setopt($handle, CURLOPT_HTTPPROXYTUNNEL, 0); 
    curl_setopt($handle, CURLOPT_PROXY, $proxy); 
    curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, 0); 
    $response = curl_exec($handle); 
    curl_close($handle); 
    header('Expires: 0'); // no cache 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); 
    header('Cache-Control: private', false); 
    header('Content-Type: application/force-download'); 
    header('Content-Disposition: attachment; filename="' . $filename . '.apk"'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Content-Length: ' . strlen($response)); // provide file size 
    header('Connection: close'); 
    echo $response; 
} 
0

は、私はのReadFileを発見した()したい場合は、プロキシをバインドサポートされていない、あなたはベースでプロキシを設定する方法を見つける必要があります。誰かがApacheを使用していると言いましたが、私はtridをhaventしません。

最後に、別の関数file_get_contents()が私の問題を解決します。

ここ

が私のコードです:

public function download_file($link='https://apkpure.co/apk/com.ezfun.p1767.dns_gp1/00b97d3d32a4f8e6cbecff7da5a4af41/1.0/0dfa1365e8e1c70bf2dcf391350a7a77/', $filename='com.ezfun.p1767.dns_gp1_1.0'){ 

    $aContext = array(
     'http' => array(
      'proxy' => 'tcp://192.168.10.3:18118', 
      'request_fulluri' => true, 
     ), 
    ); 
    $cxContext = stream_context_create($aContext); 

    $sFile = file_get_contents("https://apkpure.co/apk/com.wepie.snakeoff/6fbde5c9d65e72d4d014f9bf654bfe47/2.0/984e0be4d6a84965544692bc30487837/", False, $cxContext); 

    $path = file_put_contents(public_path().'/application.snakeoff.apk', $sFile); 

    echo $path; 

} 

file_put_contentの意志がファイルに書き込まれたバイト数、あるいは失敗した場合にFALSEを返します。

関連する問題