我正在尝试制作一个php“图像下载器”,到目前为止,一切都是我想要的。我面临的问题可能是我试图访问的服务器的某种安全性。例如,这个url将显示我想在服务器上下载的图像。
但是,如果我试图至少在我的网站上用那个网址显示那个图片,它根本就不会出现。我不能显示我的网站的网址,但它只是一个简单的<img />标签,没有别的。
有什么办法可以绕过这件事吗?还是我该辞职了?
为了明确说明我的代码没有错,我可以从其他我尝试过的网站下载任意数量的图片。不要向我要代码,因为即使是<img src="url_here.jpg" />也不起作用,所以查看php代码是没有意义的。
发布于 2013-04-03 16:47:11
是的,它不会出现,因为另一台服务器正在阻止图像的热链接。
一个典型的例子是
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yande.re/.*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]解决方案。
Cencept的证明
$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);输出

https://stackoverflow.com/questions/15793143
复制相似问题