[英]Force File Download in Safari
我正在嘗試在Safari中下載文件。 這是我的代碼:
<?php
$file = $_GET['file'];
header ("Content-Disposition: attachment");
header ("Content-type: application/octet-stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>
它在FF中工作正常,但在Safari中我得到了一個0kb的文件。
我認為我發送的標題中有問題。 可能是什么錯誤?
嘗試這個。
<?php
$file = $_GET['file'];
header('content-type: application/octet-stream');
header('content-Disposition: attachment; filename='.$file);
header('Pragma: no-cache');
header('Expires: 0');
readfile($file);
?>
注意:沒有任何衛生條件或限制而依靠$_GET['file']
是非常危險的。 可用於破壞整個服務器應用程序!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.