我寫了下面的PHP功能,但仍然得到提示要下載的文件:如何在瀏覽器中顯示以字節形式返回的圖像而不提示下載?
function navigateToBytes($contentType, $bytes){
header('Content-Type: ' .$contentType);
//header('Content-Transfer-Encoding: binary'); // UPDATE: as pointed out this is not needed, though it does not solve the problem
header('Content-Length: '.strlen($bytes));
ob_clean();
flush();
echo $bytes;
}
調用函數的例子:
navigateToBytes('image/jpeg', $bytes); // UPDATE: turns out this does work, using image/tiff for tiff images is when the browser does not display the image
其中$字節是字節從讀文件。
的文章存在疑問的內容 - 使用的處置標題,但沒有提供答案,一些評論試圖.. – markmnl 2010-12-08 07:04:50