【发布时间】:2013-08-02 16:01:55
【问题描述】:
我的脚本在本地主机上总是运行良好。现在我把我所有的图片都移到了另一个网站上,脚本不再起作用了。为什么会这样,我该如何解决?
错误:
警告:filesize(): stat failed for http://data.localsky.net/panel/img/blocked/box_main.gif in C:\xampp\htdocs\Projects\MVC\application\class.security.php 在线15
我调用函数:
baseImg('http://data.localsky.net/panel/img/blocked/box_main.gif', false);
public function baseImg($path, $auto=true) {
$img_src = $path;
$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
$img_str = base64_encode($imgbinary);
if ( preg_match('/(?i)msie [1-8]/', $_SERVER['HTTP_USER_AGENT']) ) {
if($auto) {
return '<img src="'.$img_scr.'" />';
} else {
echo $img_src;
}
} else {
if($auto) {
return '<img src="data:image/jpg;base64,'.$img_str.'" />';
} else {
return 'data:image/jpg;base64,'.$img_str;
}
}
}
【问题讨论】:
-
也许
filesize()无法处理 URL(?) -
将图像放在单独的域中,并用 php 处理它们是一个巨大的性能杀手
-
你可以使用 file_get_contents 代替