[英]PHP output image issues
if (file_exists($path)) {
$fileContent = id3_getImage($path);
$fileMime = id3_getMimeOfImage($path); // is set to image/jpeg
if ($fileMime != "") {
header('Content-Type: '.$fileMime);
print($fileContent);
die;
}
}
所以上面的代碼在瀏覽器中不起作用,但是當我用圖像制作圖像時
$img = imagecreatefromstring($fileContent);
imagejpeg($img, 'test.jpg');die;
圖像已創建,我可以在計算機上查看它。 所以我不知道我在做什么錯:(
*這可能是apache conf中的設置嗎? 老實說,我對此一無所知
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($img);
您需要先發送頭。 但是,如果要創建圖像並顯示,則需要創建並為瀏覽器閱讀。
readfile($filename);
您可以在此處閱讀該文檔: http : //php.net/manual/zh/function.readfile.php
我使用Google網上論壇的smartReadFile.php來顯示任何類型的文件。
https://jplayer.googlegroups.com/attach/f308294ddea52f6c/smartReadFile.php?view=1&part=4
真的很聰明 =)
<?php
require "smartReadFile.php";
$dir = 'images/';
$filename = 'someimage' . '.jpg';
$location = $dir.$filename;
smartReadFile($location, $filename);
?>
從數據庫讀取時,這對我有用
$image = imagecreatefromstring([path/DBfiels]);
header('content-type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.