1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/** -------------------------------------------------------------------------------
* ファイルシステム:バイナリーファイルの読込して画像を表示の利用例
* 2015.09.17 作成 yoshi of CXMedia Inc.
* -------------------------------------------------------------------------------- */
// 画像ファイルのパス
$filepath = 'data/CXMedia_logomark.png';
/* ------------------------------------------------------
* バイナリセーフなファイルの読み込み
* fread ( handle ,length )
* length:最大length バイトまで読み込む
* ------------------------------------------------------ */
if( file_exists($filepath) ){
// 画像のタイプをheader関数で指定
header('Content-Type: image/png');
// 画像などのデータは「バイナリ:b」を付加してオープン
$fh = fopen($filepath, 'rb');
$str = fread($fh, filesize($filepath));
echo $str;
fclose($fh);
} else {
// ファイルがない場合
header("Content-type:text/plain; charset=UTF-8");
echo "■ファイル・ノットファンドエラー:$filepath\n";
exit;
}
?>