virtuexru Posted May 26, 2009 Share Posted May 26, 2009 How would I mask where my images are being downloaded from (like the images on www.domain1.com are hosted on www.domain2.com, but I do not want people knowing that the images are coming from www.domain1.com). Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 26, 2009 Share Posted May 26, 2009 is there a particular reason you cannot store these images locally ? Quote Link to comment Share on other sites More sharing options...
virtuexru Posted May 26, 2009 Author Share Posted May 26, 2009 is there a particular reason you cannot store these images locally ? We have a data feed from another website that we pay for. Images are a part of this feed (they feed us their updates links into a MySQL database). I don't want people seeing where the images are being fed from though, that is the problem. Quote Link to comment Share on other sites More sharing options...
N-Bomb(Nerd) Posted May 26, 2009 Share Posted May 26, 2009 Take the link from the feed, save the image locally.. then it appears as if it's from you. ??? Quote Link to comment Share on other sites More sharing options...
virtuexru Posted May 26, 2009 Author Share Posted May 26, 2009 Take the link from the feed, save the image locally.. then it appears as if it's from you. ??? That's not the method I asked for, thanks though. Anyone else have any ideas? Maybe its possible not through PHP but through Javascript? Quote Link to comment Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi Never tried it from a remote site, but read the image from the other location into php and then write out from php complete with headers. header("Content-Type: image/gif"); readfile("http://www.domain2.com"); Might work (think it depends on a setting in the php ini file to allow remote reads like this, maybe allow_url_fopen ). All the best Keith Quote Link to comment Share on other sites More sharing options...
corbin Posted May 26, 2009 Share Posted May 26, 2009 If a server's going to remotely request it more than once, it might as well just save it. You're wasting bandwidth otherwise. Quote Link to comment Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 If a server's going to remotely request it more than once, it might as well just save it. You're wasting bandwidth otherwise. I would agree that is best practice, and to cache it locally. But I presume he doesn't want a link to a real local copy either. All the best Keith Quote Link to comment Share on other sites More sharing options...
virtuexru Posted May 26, 2009 Author Share Posted May 26, 2009 If a server's going to remotely request it more than once, it might as well just save it. You're wasting bandwidth otherwise. I would agree that is best practice, and to cache it locally. But I presume he doesn't want a link to a real local copy either. All the best Keith How would I go about saving a local copy automatically? Quote Link to comment Share on other sites More sharing options...
kickstart Posted May 26, 2009 Share Posted May 26, 2009 Hi Something like this (not tested as hacked from a script I have, so may be a typo or 2):- $CacheFileName = '/SomeCacheLocation/SomeImage.jpg'; $RemoteFileAddress = 'http://www.remotesite.com/SomeImage.jpg'; $RemoteFileName = 'SomeImage.jpg'; if (file_exists( $CacheFileName )) { header('Content-Type: image/jpg'); readfile($CacheFileName ); } else { $img = imagecreatefromstring(file_get_contents( $RemoteFileAddress )); if ($img !== false) { $thumb = imagecreatetruecolor($width, $height); if ($thumb !== false) { imagecopyresampled($thumb, $img, 0, 0, 0, 0, $width, $height); imagejpeg($thumb, $CacheFileName, 100); header("Content-disposition: attachment; filename=\"$RemoteFileName\""); header('Content-Type: image/jpg'); readfile($CacheFileName ); imagedestroy($img); imagedestroy($thumb); } } } Basically, check if the image is cached. If so just output that. If not then create an image in memory from the remote location, create another local image and specify the width and height you want (so you can create a smaller / larger copy), copy the first image to the resized local copy, write it out as a jpeg, then put out the headers and do a readfile to read the cached image and output it. All the best Keith Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.