With the following methods of retrieving files in PHP I keep on hitting an anti-hotlinking security picture rather than the image I'm looking for. The odd thing is, when I manually input the url in Firefox/IE or even Internet Download Manager I do get the correct file, so there must be something wrong with the methods I have tried so far.
file_put_contents:
file_put_contents($localpath, file_get_contents($remoteURL));
The following function didn't work either:
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);
And fopen()
$tag = fopen($remoteURL, 'rb');
if($tag){
while(!feof($tag)) {
$imgt = $imgt . fread($tag, 1024);
}
}
and imagecreatefromjpeg() didn't do the trick either
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;
}
Do I have any other options?