我嘗試使用PHP來強制圖片JPG文件下載,我ETH下面的代碼來實現:文件損壞時,點擊下載鏈接
HTML
<a href = "filedownload.php?src=uploads/myimage.jpg&download=true>download this file</a>
的download.php
<?php
ob_start();
include_once 'functions.php';
if (isset($_GET['download']) && $_GET['download'] == 'true')
{
$src = sanitizeString($_GET['src']);
header('Content-Description: File Transfer');
header('Content-Type: image/jpeg');
header('Content-Disposition: attachment; filename='.basename($src));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: public');
header('Pragma: public');
}
?>
假設圖像的完整路徑是「www.example.com/smith/topic/uploads/myimage.jpg」,我已經收到了正確的圖像名稱,同時也出現了下載窗口,但圖像已損壞,並且1KB大小,任何人都可以告訴我爲什麼,非常感謝。
什麼是裏面的文件?我敢打賭,啤酒中有一個PHP錯誤信息,它解釋了哪裏出了問題。 –
哪個代碼?這是我得到的所有部分 – smith
首先,在PHP腳本的開頭有一個空格,這是一個不允許的。你也忘了「在你的href結尾,你甚至會在那裏打印文件內容嗎?PS:我強烈推薦處理這樣的文件,潛在攻擊的地方太多了 –