Jump to content

Recommended Posts

<?php

if (isset($_GET['tag'])) {

  do_search($_GET['tag']);

} else {

?>

    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="get">

    <p>Search for photos with the following tag:

    <input type="text" size="20" name="tag"/> <input type="submit" value="Go!"/></p>

    </form>

<?php

}

?>

<?php

 

# uses libcurl to return the response body of a GET request on $url

function getResource($url){

  $chandle = curl_init();

  curl_setopt($chandle, CURLOPT_URL, $url);

  curl_setopt($chandle, CURLOPT_RETURNTRANSFER, 1);

  $result = curl_exec($chandle);

  curl_close($chandle);

 

  return $result;

}

 

function do_search($tag) {

  $tag = urlencode($tag);

 

#insert your own Flickr API KEY here

 

  $api_key = "1a2755a9a5a19904c7f5e661d85db657";

  $per_page="100";

  $url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key={$api_key}&tags={$tag}&per_page={$per_page}";

 

  $feed = getResource($url);

  $xml = simplexml_load_string($feed);

  print "<p>Total number of photos for {$tag}: {$xml->photos['total']}</p>";

 

# http://www.flickr.com/services/api/misc.urls.html

# http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg

foreach ($xml->photos->photo as $photo) {

  $title = $photo['title'];

  $farmid = $photo['farm'];

  $serverid = $photo['server'];

  $id = $photo['id'];

  $secret = $photo['secret'];

  $owner = $photo['owner'];

  $thumb_url = "http://farm{$farmid}.static.flickr.com/{$serverid}/{$id}_{$secret}_t.jpg";

  $page_url = "http://www.flickr.com/photos/{$owner}/{$id}";

  $image_html= "<a href='{$page_url}'><img alt='{$title}' src='{$thumb_url}'/></a>";

  print "<p>$image_html</p>";

}

 

} # do_search

?>

 

I want to display 300 photos horizontally so they fill the web page - at the moment the script just displays 20 photos vertically.

 

Link to comment
https://forums.phpfreaks.com/topic/265587-how-can-i-modify-this-script/
Share on other sites

To get them to display vertically, you could float the <p> tag with CSS.

print "<p>$image_html</p>";

 

For more information, you could search for "creating an image gallery with css".

 

 

 

As a side note, I would recommend avoiding PHP_SELF in the form action attribute for security reasons. Instead, you could just list the page name...or leave it blank.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.