はい、他のサーバーが画像のホットリンクを妨げているため、表示されません。
典型的な例は
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yande.re/.*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]
ソリューション。
- curl で画像を読み込む
- CDN に保存する
- 次に、サイトに表示します
プルーフ・オブ・セセプト
$url = 'https://yande.re/sample/2f7b6c5d87d90f173769d999e60861c8/yande.re%20250521%20sample.jpg';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31");
curl_setopt($ch, CURLOPT_REFERER, "https://yande.re");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
// $data is file data
$post = array('image' => base64_encode($data), 'key' => "YOUR_API_KEY_ITS_FREE");
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.json');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
$json = curl_exec($curl);
curl_close ($curl);
$json = json_decode($json);
printf("<img src\"%s\" / >",$json->upload->links->small_square);
出力
