Jump to content

Random Picture From Your Coppermine Gallery


javaguy

Recommended Posts

You'll need to put in your username, password and database name and may need to tweak the file path to match your setup. Save this to a file called randompic.php and put a tag in a page like this:

><img src="randompic.php">

 

 

><?php
header("Content-type: image/png");


//Select random thumbnail file.
$link = mysql_connect('localhost', 'username', 'PASSWORD')
or die('Could not connect: ' . mysql_error());
mysql_select_db('album_db') or die('Could not select database');

// Performing SQL query
$query = "SELECT filepath, filename FROM cpg135_pictures ORDER BY rand() limit 1";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
$filepath = 'album/albums/' . $line['filepath'];
$filename = $line['filename'];
mysql_free_result($result);
mysql_close($link);

$thumbnail_img = imagecreatefromjpeg($filepath . '/' . $filename);

imagejpeg($thumbnail_img);

imagedestroy($thumbnail_img);

?>

Link to comment
Share on other sites

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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