views:

28

answers:

1

Hey guys, I'm struggling with grabbing an image at the moment... sounds silly, but check out this link :P

http://manga.justcarl.co.uk/A/Oishii_Kankei/31/1

If you get the image URL, the image loads. Go back, it looks like it's working fine, but that's just the browser loading up the cached image.

The application was working fine before, I'm thinking they implemented some kind of Referer check on their images. So I found some code and came up with the following...

$ref = 'http://www.thesite.com/'; 
$file = 'theimage.jpg';
$hdrs = array( 'http' => array(
 'method' => "GET",
 'header'=> "accept-language: en\r\n" . 
  "Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*\/*;q=0.5\r\n" .
  "Referer: $ref\r\n" . // Setting the http-referer
  "Content-Type: image/jpeg\r\n" 
 )
);
// get the requested page from the server
// with our header as a request-header
$context = stream_context_create($hdrs);

$fp = fopen($imgChapterPath.$file, 'rb', false, $context);
fpassthru($fp);
fclose($fp);

Essentially it's making up a false referrer. All I'm getting back though is a bunch of gibberish (thanks to fpassthru) so I think it's getting the image, but I'm afraid to say I have no idea how to output/display the collected image.

Cheers, Carl

A: 

Try calling this before your call to fpassthru:

header('Content-Type: image/jpeg');

This will tell your browser that the data coming next is a JPEG image. Otherwise PHP will automatically say it's a HTML document, which is obviously wrong.

Note: Remember that all calls to header must be made before anything else is output to the browser, which means you cannot have any echo or print calls before calling header, and you cannot have anything at all before the opening <?php tag.

Emil Vikström
Strange, it's sending a Referer with this method and the image still loads. Sadly I'm loading the image in a html document so I can't use this method, more work it seems ^^ hehe, thanks for the help
Mr Carl