2015-06-11 79 views
0

我實現了使用curl擴展名下載一些(.exe)文件的php函數。該文件成功下載,但只在Firefox中,它們的擴展名是「file.exe.html」。這裏是我的功能:firefox使用curl將下載的exe文件的擴展名更改爲html

$source = isset($_GET['link']) ? $_GET['link'] : ''; #get the download link 
$filename = isset($_GET['name']) ? $_GET['name'] : 'download.exe'; # define name 
if($source != '') 
{ 
     $handle = curl_init($source); 
     curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); 

     /* Get the HTML or whatever is linked in $url. */ 
     $response = curl_exec($handle); 

     /* Check for 403 (forbidden). */ 
     $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); 
     if($httpCode == 403) { 
      echo "<h2> <font color='red'> Sorry you are not allowed to download that file.</font><h2>"; 
     } else { 
      header("Content-Disposition: attachment; filename=\"{$filename}\""); 
      #header("Content-Disposition: attachment; filename=\"uploaded.pdf\""); 
      // Get a FILE url to my test document 

      $url= str_replace(" ","%20", $source); 
      $ch= curl_init($url); 
      #curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); 
      curl_setopt($ch, CURLOPT_HEADER, false); 
      curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); ## just tried it 
      curl_exec($ch); 
      curl_close ($ch); 
     } 
     curl_close($handle); 
} 
else { 
    echo "error"; 
} 

回答

0

請嘗試定義文件的類型,添加 標題( '內容類型:應用程序/ x-ms的應用程序');

相關問題