后端接口读取图片文件并输出到浏览器,既可以将资源文件的引用接口化,又能稍处理实现反爬虫,很不错呦。
怎么样?简单吧?
代码如下:
$file = "/home/yixzm/imgs/beauty.jpg";
header('Content-type:image/png');
echo file_get_contents($file);
OK!
function load_img()
{
$file = "/home/yixzm/imgs/beauty.jpg";
header('Content-type:image/png');
echo file_get_contents($file);
}
<?php
namespace utils\load_img;
class load_img
{
public function __construct()
{ }
static function create()
{
static $instance;
if (!$instance) {
$instance = new load_img();
}
return $instance;
}
function load_img()
{
$file = "/home/yixzm/imgs/beauty.jpg";
header('Content-type:image/png');
echo file_get_contents($file);
}
}