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
<?php
/** -------------------------------------------------------------------------------
* ファイルシステム:バイナリセーフなファイルの読込して表示の利用例
* 2015.09.17 作成 yoshi of CXMedia Inc.
* -------------------------------------------------------------------------------- */
// 画像ファイルのパス
$filepath = 'data/CXMedia_logomark.png';
/* -----------------------------------------------------------------------------------
* バイナリセーフなファイルの内容を全て文字列に読み込む
* file_get_contents ( filename [,use_include_path [,context [,offset [,maxlen ]]]] )
* maxlen:デフォルトは、ファイル終端まで読み込み
* ----------------------------------------------------------------------------------- */
if( file_exists($filepath) ){
// 画像のタイプをheader関数で指定
header('Content-Type: image/png');
// 画像を読み込んで、画像内容を表示
echo file_get_contents( $filepath );
} else {
// ファイルがない場合
header("Content-type:text/plain; charset=UTF-8");
echo "■ファイル・ノットファンドエラー:$filepath\n";
exit;
}
?>