will choose second image in the gallery as the thumb. this drastically speeds up page loads, especially during dev
<?php
$dbserver = 'localhost';
$dbuser = 'foo';
$dbpass = 'bar';
$dbname = 'photozen';
$zprootdir = 'C:/xampp/htdocs/zp/albums/'; // full file path to albums dir
mysql_connect($dbserver, $dbuser, $dbpass);
mysql_select_db($dbname);
$query = 'SELECT id, folder FROM zp_albums WHERE thumb is NULL AND parentid IS NOT NULL';
$rs = mysql_query($query);
while (($row = mysql_fetch_assoc($rs))){
// choose second image from dir
$images = glob($zprootdir . $row['folder'] . '/*.{jpg,JPG,jpeg,png,gif}', GLOB_BRACE);
natsort($images);
$thumb = $images[1]; // change to choose the number image you want as thumb (always one less)
// keep just filename remove 'sites/site-title'
$thumb = substr($thumb, strrpos($thumb, '/')+1);
// update db
mysql_query("UPDATE zp_albums SET thumb = '" . mysql_real_escape_string($thumb) . "' WHERE id = " . $row['id']);
}
die ("all done");
?>
Comments
However, You might just want to choose the thumbnail from the album edit page. There you can choose from any image in the album.
The only reason you'd do this, as george2 said, is if you're developing and don't want to load/process thumbnails from large albums.
You get the same effect in production by just setting the album thumb manually, which you'd probably want to do anyway.
Here is the gallery in question:
http://www.lindsayhutchens.com/archive
Thanks!