well I just got doen with a big project
what it does is the following:
- Index directory/Subdirectory to mysql
- Gets Images file names puts them into mysql
- Gets file size puts them into mysql
- Ceates thumbnails
- Creates Directorys if you need them
heres the merge script, there are other scripts but check this out..
<?
//*********************************************************\\
// Name: Merge Script
// Programmer: Derrick Rose
// Date: Dec 16, 2002
// Summery: Thumbnail/Indexing Script
//**********************************************************\\
include('cfg.php');
function thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
{
$src_img = imagecreatefromjpeg("$image_path/$image_name");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
$new_w = $thumb_width;
$diff=$origw/$new_w;
$new_h=$new_w;
$dst_img = imagecreate($new_w,$new_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, "$thumb_path");
return true;
}
function mkpath($path,$mode = 0700) {
$dirs = explode("\\",realpath($path));
$path = $dirs[0];
for($i = 1;$i < count($dirs);$i++) {
$path .= "\\".$dirs[$i];
if(!is_dir($path))
mkdir($path,$mode);
}
}
function getDirList ($dirName) {
$d = dir($dirName);
while($entry = $d->read()) {
if ($entry != "." && $entry != ".." && $entry != "index.php" && $entry != "cfg.php") {
if (is_dir($dirName."\\".$entry)) {
getDirList($dirName."\\".$entry);
} else {
//**********************************************************\\
// Edit the BasePath to the directory path of the scripts \\
//**********************************************************\\
$basePath = "C:\\Inetpub\\wwwroot\\photolab\\";
//Start code
$partialPath = substr($dirName,strlen($basePath), strlen($dirName) - strlen($basePath));
$thumbnail = "thumbnail\\".$partialPath."\\thumb_".$entry;
$thumbnail2 = "thumbnail\\".$partialPath;
$partialPath2 = "images\\".$partialPath;
$partialPath2 = addslashes($partialPath2);
$partialPath = addslashes($partialPath);
$entry = addslashes($entry);
$thumbnail = addslashes($thumbnail);
//'Database Connection
$server_host = "localhost"; // Server IP/HOST
$user_name = "root"; // User name
$user_pass = ""; // Password
$server_database = "Photos"; //Database
$connect = mysql_connect($server_host, $user_name, $user_pass) or die ("Couldnt connect");
$db = mysql_select_db($server_database, $connect) or die ("Couldnt open Database");
$check_query = "SELECT * FROM Photos WHERE PhotoName='$entry' AND PhotoLocation='$partialPath'";
$results = mysql_query($check_query, $connect);
if (mysql_num_rows($results) == 0) {
// CHECK FILE SIZE
$filesize = filesize("$partialPath\\$entry");
if ($file_size >= 1073741824) {
$filesize = number_format(($filesize / 1073741824),2) . " GB";
$filesize2 = "Big";
} elseif ($filesize >= 1048576) {
$filesize = number_format(($filesize / 1048576),2) . " MB";
$filesize2 = "Big";
} elseif ($filesize >= 1024) {
$filesize = number_format(($filesize / 1024),2) . " KB";
$filesize2 = "Small";
} elseif ($file_size >= 0) {
$filesize = $filesize . " bytes";
$filesize2 = "Small";
} else {
$filesize = "0 bytes";
$filesize2 = "Small";
}
//GET IMAGE TYPE
$image_size = getimagesize("$partialPath\\$entry");
if ($image_size[2] == "1") {
$image_type = "GIF Image";
} elseif ($image_size[2] == "2") {
$image_type = "JPEG Image";
} elseif ($image_size[2] == "3") {
$image_type = "PNG Image";
} elseif ($image_size[2] == "4") {
$image_type = "SWF Image";
} elseif ($image_size[2] == "5") {
$image_type = "PSD Image";
} elseif ($image_size[2] == "6") {
$image_type = "BMP Image";
} elseif ($image_size[2] == "7") {
$image_type = "TIFF Image";
} else {
$image_type = "Unknown Image";
}
//Create Thumbnail
$testdir = is_dir("thumbnail\\$partialPath");
//Check to make sure thumbnail has a place to go if not create folder(s)
if (!$testdir) {
//**************************
//Here we go....
//**************************
echo "<b><font color=orange>No Directory: thumbnail\\".$partialPath."</font><b><br>";
mkpath("thumbnail\\$partialPath");
if(eregi(".*jpg", $entry)) {
echo "<b><font color=orange>Creating: thumbnail\\".$partialPath."</font></b><br>";
thumbnail("$partialPath\\","$thumbnail","$entry","100");
echo "<b><font color=blue>Created Thumbnail:</b></font><i> $partialPath\\thumb_$entry </i><br>";
$sql = "INSERT INTO Photos SET PhotoImageType = '$image_type', PhotoName = '$entry', PhotoLocation = '$partialPath', PhotoThumbnail = '$thumbnail', PhotoType = '$filesize2', Photosize = '$filesize'";
$sql_result = mysql_query($sql, $connect) or die ("Could not insert user into database");
echo "<b>Merging:</b> <i>".$partialPath."\\".$entry."</i><br>";
}
} else {
if(eregi(".*jpg", $entry)) {
thumbnail("$partialPath\\","$thumbnail","$entry","100");
echo "<b><font color=blue>Created Thumbnail:</b></font><i> $partialPath\\thumb_$entry </i><br>";
//Insert SQL Statment
$sql = "INSERT INTO Photos SET PhotoImageType = '$image_type', PhotoName = '$entry', PhotoLocation = '$partialPath', PhotoThumbnail = '$thumbnail', PhotoType = '$filesize2', Photosize = '$filesize'";
$sql_result = mysql_query($sql, $connect) or die ("Could not insert user into database");
echo "<b>Merging:</b> <i>".$partialPath."\\".$entry."</i><br>";
}
}
} else {
echo "<b>Already Merged:</b> <i>".$partialPath."\\".$entry."</i><br>";
echo "<b><font color=red>Already Thumbnailed:</b></font><i>$partialPath\\thumb_$entry</i><br>";
}
mysql_close($connect);
}
}
}
$d->close();
}
getDirList("$image_location");
?>