【发布时间】:2011-09-10 22:10:49
【问题描述】:
通过以下在 PHP 中检索文件的方法,我不断点击反盗链安全图片,而不是我正在寻找的图片。奇怪的是,当我在 Firefox/IE 甚至 Internet 下载管理器中手动输入 url 时,我确实得到了正确的文件,所以我到目前为止尝试的方法一定有问题。
file_put_contents:
file_put_contents($localpath, file_get_contents($remoteURL));
以下功能也不起作用:
function save_image($inPath,$outPath)
{ //Download images from remote server
$in= fopen($inPath, "rb");
$out= fopen($outPath, "wb");
while ($chunk = fread($in,8192))
{
fwrite($out, $chunk, 8192);
}
fclose($in);
fclose($out);
}
save_image($remoteURL,$localpath);
和 fopen()
$tag = fopen($remoteURL, 'rb');
if($tag){
while(!feof($tag)) {
$imgt = $imgt . fread($tag, 1024);
}
}
而 imagecreatefromjpeg() 也没有做到这一点
function LoadJpeg($imgname)
{
/* Attempt to open */
$im = @imagecreatefromjpeg($imgname);
/* See if it failed */
if(!$im)
{
/* Create a black image */
$im = imagecreatetruecolor(150, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an error message */
imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
}
return $im;
}
我还有其他选择吗?
【问题讨论】:
-
问题可能是您发送的 HTTP Referer 标头的值。该网站故意试图阻止你做你想做的事——在不先浏览他们的网页的情况下获取图像。您也可能违反了他们的条款和条件 - 您应该在继续之前阅读这些条款和条件。
-
你的php.ini系统中
allow_url_fopen的值是多少? -
@atma 开着了,不可能是这样
标签: php