Jump to content

How can i modify this script?


xymalf

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.