2017-04-13 47 views
0

我有一個php文件,當你打開它時,圖片將被下載並打開。這裏是我的代碼:http請求到php流圖像

header('Content-type: image/jpeg'); 
$stream = fopen('php://output', 'w'); // Stream to browser like with echo 
$MadelineProto->download_to_stream($messageMediaPhoto, $stream); 

沒關係,直接打開。但是當我向頁面發送ajax請求時,我會遇到一些很長的奇怪字符。 (我想顯示圖像在HTML src

任何想法,將不勝感激。

回答

1

您需要將您的php文件添加到圖片標籤的src屬性中。例如,如果您的php文件被稱爲image.php,那麼您可以使用以下html代碼來顯示圖像:

<img src='image.php' width='image-width-in-px' height='image-height-in-px' /> 
+0

是的,這是一個很好的解決方案。但我想知道是否有辦法以base64_encoded格式獲取圖像。因爲在這種情況下,我無法顯示任何微調或特殊的Angular加載欄。順便說一聲謝謝。 –

+0

您可以使用base64編碼格式獲取圖像。一個例子是:Embedded Image。看到這個相關的職位:http://stackoverflow.com/questions/1207190/embedding-base64-images –