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). Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/ 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 ? Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842441 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. Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842448 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. ??? Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842452 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? Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842472 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 Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842479 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. Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842484 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 Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842488 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? Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842519 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 Link to comment https://forums.phpfreaks.com/topic/159719-masking-the-source-of-images/#findComment-842530 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.