Hi, I was going through old files on mediafire, and found a few useful php scripts, so here's a source code to grab the movie image/post from IMDB based on the movie named passed through in the function/param. <?php /** * Grab Movie Poster from IMDB to display on hover * * @author Vick Kumar <vickkumar2011@gmail.com> * @copyright Seecure.me, 2012 * @version 1.0 * @license http://creativecommons.org/licenses/by/3.0/legalcode */ function getImage($title) { $source = file_get_contents("http://www.imdbapi.com/?i=&t=$title"); $decode = json_decode($source, true); return $decode['Poster']; } ?> PHP:
Have you tested it? Does it work or has IMDB changed since this code was valid? there are lots of code on mediafire - how does this rate compared to other IMDB scripts? And why have you posted it? Is it a personal recommendation, are you hoping someone might be overcome with gratitude and give you a "like"?
Yeah man. It works !, and like I said I posted it cause I thought it would be useful to share, and if not go ahead and delete it, your the queen.
In case anybody couldn't get the above to work; <?php $homepage = file_get_contents('http://www.imdbapi.com/?t=The%20Holiday'); $arr = json_decode($homepage, true); print($arr['Poster']); ?> PHP: To see all the data you can grab: <?php $homepage = file_get_contents('http://www.imdbapi.com/?t=The%20Holiday'); $arr = json_decode($homepage, true); print($homepage); ?> PHP:
^ In regards to that. Awesome ! Also, if you do use it and you want to do bulk processing I recommend using CURL instead of file_get_contents !
Yes CURL would probably be better at handling larger amounts of data, here's an example of usage using the URL to get the movie title: <?php $title = rawurlencode($_GET['title']); //optional comment out or delete error_reporting(E_ALL); // The POST URL and parameters $request = 'http://www.imdbapi.com/?t='.$title.'&r=XML'; // Get the curl session object $session = curl_init($request); // Set the POST options. curl_setopt($session, CURLOPT_HEADER, true); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do the POST and then close the session $response = curl_exec($session); curl_close($session); // Get HTTP Status code from the response $status_code = array(); preg_match('/\d\d\d/', $response, $status_code); // Check for errors switch( $status_code[0] ) { case 200: // Success break; case 503: die('Service unavailable. An internal problem prevented us from returning data to you.'); break; case 403: die('Forbidden. You do not have permission to access this resource, or are over your rate limit.'); break; case 400: // You may want to fall through here and read the specific XML error die('Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.'); break; default: die('Your call returned an unexpected HTTP status of:' . $status_code[0]); } // Get the XML from the response, bypassing the header if (!($xml = strstr($response, '<?xml'))) { $xml = null; } // Output the XML $movieInfo = simplexml_load_string($xml); echo "Title: ".$movieInfo->movie['title']."<br />Poster: ".$movieInfo->movie['poster']."<br />"; ?> PHP: Slightly modified from this example: http://stackoverflow.com/questions/6932838/php-curl-error-after-changing-only-url I think another process to actually grab and save the image would be needed as IMDB do not allow embedding on their images so you'll only get the image URL and not be able to do anything with it. Its also worth noting that according to their T&C: http://www.imdb.com/help/show_article?conditions
Thats right, so it's better to use an API provided by a third-party rather than suffer financial disputes with IMDB's law team.