我有下面的PHP代碼:設置內容類型標題前的PHP回顯?
function download_file($file, $description=null, $filename=false){
$filename = $filename || basename($file);
ob_start();
if(is_string($description)){
$description = preg_replace("/\$1/", $filename, $description);
echo $description;
}
sleep(2);
header('Content-Type: '.$this->file_mimetype($file));
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file) . "\"");
readfile($file);
header("Content-Type: text/html");
ob_end_flush();
}
download_file("https://raw.githubusercontent.com/Gethis/ED/master/easydevop.class.php", "Downloading easydevop.class.php");
的問題是,它不附和「下載easydevop.class.php」下載之前。我也試過在所有標題後迴應它,但那也不起作用。請幫忙嗎?
正如你可以看到我沒有使用ob_start()
和ob_end_flush()
或標題重定向:'header('Refresh:http:// ....');' – Marek
或Location:Header – Farkie