使用下面的PHP检索文件的方法,我会不断地点击一个防盗链的安全图片,而不是我正在寻找的图片。奇怪的是,当我在Firefox/IE甚至是Internet Download Manager中手动输入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;
}我还有其他选择吗?
发布于 2011-09-11 07:10:12
如果这不是你的网站,那么你几乎无能为力。该网站的建立是为了阻止人们丢弃他们的图片或在他们的链接中使用它们。
但是,您可以使用curl语句而不是file_get_contents,如果这不起作用,请使用curl在请求中发送一些浏览器标题。
如果这是你的网站,如果你在cPanel上运行,在安全部分有一个选项。我忘了具体在哪了。
发布于 2011-09-11 08:08:00
既然您写了allow_url_fopen是on,而function不工作,您可以尝试使用curl。
function save_image($inPath,$outPath){
$ch = curl_init ($inPath);
curl_setopt($ch, CURLOPT_HEADER, 0); // required
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); // required for images
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // maybe redirect on other side?
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'); // or user agent checks?
$rawdata=curl_exec($ch);
curl_close ($ch);
if(file_exists($outPath)){
@unlink($outPath);
}
$fp = fopen($outPath,'x');
fwrite($fp, $rawdata);
fclose($fp);
}发布于 2011-09-11 07:15:52
他们这边可能有一些检查,他们可能得到了用户代理,推荐人。尝试将此用于fake浏览器的行为
https://stackoverflow.com/questions/7375021
复制相似问题