2012-04-21 51 views
1
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; 
    } 
} 

所以上面的代碼在瀏覽器不能正常工作,但是當我做一個圖像與圖像PHP輸出圖像發出

$img = imagecreatefromstring($fileContent); 
imagejpeg($img, 'test.jpg');die; 

創建映像,我可以看到它在我的電腦上。所以,我不知道我在做什麼錯:(

*難道是在Apache的conf設置?說實話,我在這一個

+0

我需要動態創建的圖像讀取時這一個是爲我工作,所以它不是真正創建圖像,然後將其重定向到路徑的選項。無論如何,它應該這樣工作,雖然 – 2012-04-21 20:30:24

+0

只是使用'imagejpeg($ img,NULL);' – smocking 2012-04-21 20:30:48

+0

請解釋id3_getImage()和id3_getMimeOfImage() - 這些不是有效的運算符。 – 2012-04-21 20:41:29

回答

0
header('Content-Type: image/jpeg'); 

// Output the image 
imagejpeg($img); 

您需要發送頭不知道。但如果你要創建的圖像,並顯示,你需要創建和讀取此爲瀏覽器

readfile($filename); 

你可以在這裏閱讀的人: http://php.net/manual/en/function.readfile.php

+0

我不確定你的意思,你不需要使用readfile($ filename),因爲該文件的內容與$ var相同並且它們都將它打印到瀏覽器 – 2012-04-21 20:34:47

+0

您需要使用'imagejpeg($ img,'test.jpg');'並使用readfile('test.jpg');' – 2012-04-21 20:37:30

+0

我不確定,因爲我以爲它會有相同的輸出,但是我已經測試過了,沒有結果:( – 2012-04-21 20:40:52

0

我用SMARTR Google Groups的eadFile.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); 

?> 
+0

使用這個,仍然不起作用,我想我需要在我的apache conf中改變一些東西。由於該網址沒有擴展名.jpg,實際上它沒有任何擴展名。這只是/ cover/ – 2012-04-21 20:38:48

+0

與URL無關。這是一個文件目錄閱讀。 – 2012-04-21 20:42:05

0

從DB

$image = imagecreatefromstring([path/DBfiels]); 
header('content-type: image/jpeg'); 
imagejpeg($image); 
imagedestroy($image); 
+0

不幸的是,不適合我。 – 2012-04-21 20:48:54