Forum Moderators: coopster

Message Too Old, No Replies

Asp script to php code !?

asp to php cURL functions

         

numediaweb

10:09 am on May 19, 2008 (gmt 0)

10+ Year Member



I made a script that "parses" an external html page and extract an image information and link from that page, then show it with an echo statement.
I discouvered that the site i'm trying to get images from has some kind of protection, imdb.com tries to write a cookie and if your page is not on their domain it will fail due to cross site scripting and the image will show as broken.
Carlo from carlovella.com developped an asp function that bypasses this protection; <snip>

byte[] bytes = HttpHelper.GetImdbImage(url);
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.ContentType = “image/jpeg”;

public static byte[] GetImdbImage(string url)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
return getImageBytes(System.Drawing.Image.FromStream(webResponse.GetResponseStream()));
}

This was in asp, can someone "translate" it to php? with source code?

thank you guys.

PS: I run PHP Version 4.4.8

[edited by: dreamcatcher at 11:25 am (utc) on May 19, 2008]
[edit reason] No urls please! [/edit]

numediaweb

11:26 am on May 19, 2008 (gmt 0)

10+ Year Member



RESOLVED
Thanx to [curl.haxx.se...] for providing a script that handles what I needed !

[PHP]$data = 'http://example.com/example.jpg';
// Allocate a new cURL handle
$ch = curl_init($data);
if (! $ch) {
die( "Cannot allocate a new PHP-CURL handle" );
}

// We'll be returning this transfer, and the data is binary
// so we don't want to NULL terminate
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);

// Grab the jpg and save the contents in the $data variable
$data = curl_exec($ch);

// close the connection
curl_close($ch);

// Set the header to type image/jpeg, since that's what we're
// displaying
header("Content-type: image/jpeg");

// Output the image
print( $data );[/PHP]