我实现了一个php函数,它使用curl扩展名下载一些(.exe)文件。该文件已成功下载但仅在Firefox中,其扩展名为“file.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 :(得分:0)
请尝试定义文件类型,添加 header('Content-Type:application / x-ms-application');