接続でHTTPS/SSLを使用する場合は、base64でエンコードされた文字列として画像ファイルを読み取り、データ文字列を出力しようとしています。それ以外の場合は、HTTPのみの場合はIMGsrc属性にURLを出力します。これが私の現在のコードですが、機能しません。
<?php
function base64_encode_image($filename, $filetype) {
if (($_SERVER["HTTPS"] == "on") && $filename) {
$file = "/home/content/61/9295861/html/resource/image$filename";
$imgbinary = fread(fopen($file, "r"), filesize($file));
return "data:image/$filetype;base64," . base64_encode($imgbinary);
} else {
return $filename;
}
}
?>
<img src="<?php echo base64_encode_image('/resource/image/logo-96x72.png', 'png'); ?>" width="96" height="72" />
以下を出力します。
<img src="<br />
<b>Warning</b>: fopen(/home/content/61/9295861/html/resource/image/resource/image/logo-96x72.png) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: No such file or directory in <b>/home/content/61/9295861/html/theme/latest/index.php</b> on line <b>5</b><br />
<br />
<b>Warning</b>: filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for /home/content/61/9295861/html/resource/image/resource/image/logo-96x72.png in <b>/home/content/61/9295861/html/theme/latest/index.php</b> on line <b>5</b><br />
<br />
<b>Warning</b>: fread() expects parameter 1 to be resource, boolean given in <b>/home/content/61/9295861/html/theme/latest/index.php</b> on line <b>5</b><br />
data:image/png;base64," width="96" height="72" />