I have an xml file called singers.xml. I have singers in it, and the file looks like this:
<singers>
<name>tiesto</name>
<name>benny benassi</name>
..........
</singers>
What I essentially want is that I can for each singer ONE BY ONE search and find 4 images, click and choose one image, download the image and add the singer to the database.
I have this function to search for the images:
function getImgUrl($name) {
$url = 'http://ajax.googleapis.com/ajax/services/search/images?';
$manual = 'http://localhost:8080/';
$args = array(
'v' => '1.0',
'q' => $name,
'as_filetype' => 'jpg',
'imgsz' => 'medium',
'safe' => 'active',
'as_filetype' => 'jpg'
);`
foreach($args as $key => $val) {
$url .= $key . '=' . rawurlencode($val) . '&';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $manual);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body, true);
$results = $json['responseData']['results'];
return $results;
}
And I’m using it like so:
foreach($xml as $key => $val) {
$results = getImgUrl($val);
foreach($results as $result) {
echo '<img src="' . $result['url'] . '" alt="" /><br />';
}
}
But there is a problem with this code. Like I said, what I want is to see the images for each singer one by one and after I choose an image, move along to the next image.
Is that possible?
I’m not sure I fully understand the question, but here’s my suggestion.
Start with getting the XML with all singers and store it on the server as a list of singers that you want an image for.
The web application can get the first item on list, and build the page to select an image. Submit your choice back to the server, store the image and take the singer of the list, and repeat the sequence.
Does that make any sense?