0

Web サイトから .ico-Images を読み取り、その情報をデータベースに保存し、後でその画像をグローバル Web サイトに表示したいと考えています。

画像を文字列でデータベースに保存することができました。ウェブサイトに画像を表示する手順は私の問題です。

目次を読むには:

$data=file_get_contents("http://www.google.com/favicon.ico");
$data = base64_encode($data);  

その画像を Web サイトの単一の div に表示する正しい方法は何ですか?

フェスプ

4

1 に答える 1

0

基本的に、コンテンツを ico タイプとして出力するようにスクリプトに指示する必要があります。

<?php 
//Getting your image
$data=file_get_contents("http://www.google.com/favicon.ico");
$data = base64_encode($data);  

//If your storing in the db then you do the query ect togo get the data string

//Then echo out like this
header('Content-Type: image/vnd.microsoft.icon');
echo base64_decode($data);
?>

ヘッダーを設定する前に何も出力できないことを覚えておいてください。おそらく、ファイルを取得して出力するための別のスクリプトが必要になるでしょう。

<img src="get_ico.php?id=1"/>

次にget_ico.php

<?php 
//Connect db ect

//Query db for $_GET['id']

//Then echo out like this
header('Content-Type: image/vnd.microsoft.icon');
echo base64_decode($row['image_data']);
?>
于 2012-05-08T17:33:03.520 に答える