BroChris
07-01-2004, 11:06 PM
Trying to get a simple image gallery working. The code does exactly what I want it to do, but I noticed that after it creates the thumbnails, the thumbnails cannot be deleted. Any idea why? Here's the code:
<?php
ini_set("max_execution_time", 5000000);
$width=100; // width of thumbnail size
$row = 4; // number of rows in the thumbnail table
$quality = 70;
$dir = ".";
$result = opendir($dir);
echo("<b>Admin</b><br><br>\n");
echo("<form method=post action=admin.php>\n");
echo("<select name=convert_dir>\n<option value=no>Select a directory\n");
while ($fn = readdir($result))
{
if ($fn != "." AND $fn != ".." AND is_dir($fn) AND !strstr($fn,'thumbnail_'))
{
if (!is_dir('thumbnail_'.$fn))
{
echo("<option value = \"$fn\">$fn\n");
}
}
}
closedir($result);
echo("</select><br><br>\n");
echo("<input type=submit value=\"Make Thumbnail\">\n</fonm><br>");
if (isset($_POST['convert_dir']) && $_POST['convert_dir'] != 'no')
{
$dir = $_POST['convert_dir'];
$opend = 'thumbnail_'.$dir;
@$opend_result = mkdir ($opend , 0777);
if ($opend_result)
{
$result = opendir($dir);
while ($fn = readdir($result))
{
if ($fn != "." AND $fn != ".." AND !is_dir($fn) AND stristr($fn,'jpg') )
{
// Resize Photo
//echo ($fn."<br>");
$size = getimagesize($dir."/".$fn);
//echo($size[0]." ".$size[1]."<br>");
if ($size[0] <= $width)
{
//copy
$copyfile = $opend."/".$fn;
$original_file =$dir."/".$fn;
copy($original_file , $copyfile);
}
else
{
$factor = $size[0] / $width;
$new_length = intval($size[1] / $factor);
$src_img = imagecreatefromjpeg($dir."/".$fn);
$dst_img = imagecreatetruecolor($width,$new_length);
$src_width=imagesx($src_img);
$src_height=imagesy($src_img);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $new_length, $src_width, $src_height);
imagejpeg($dst_img, $opend."/".$fn, $quality);
imagedestroy($src_img);
imagedestroy($dst_img);
}
}
}
closedir($result);
echo("<br><br><b>Done!</b><br>");
}
}
?>
I tried deleting the files both through ftp and cpanel. I'm really stumped on this one...help!
<?php
ini_set("max_execution_time", 5000000);
$width=100; // width of thumbnail size
$row = 4; // number of rows in the thumbnail table
$quality = 70;
$dir = ".";
$result = opendir($dir);
echo("<b>Admin</b><br><br>\n");
echo("<form method=post action=admin.php>\n");
echo("<select name=convert_dir>\n<option value=no>Select a directory\n");
while ($fn = readdir($result))
{
if ($fn != "." AND $fn != ".." AND is_dir($fn) AND !strstr($fn,'thumbnail_'))
{
if (!is_dir('thumbnail_'.$fn))
{
echo("<option value = \"$fn\">$fn\n");
}
}
}
closedir($result);
echo("</select><br><br>\n");
echo("<input type=submit value=\"Make Thumbnail\">\n</fonm><br>");
if (isset($_POST['convert_dir']) && $_POST['convert_dir'] != 'no')
{
$dir = $_POST['convert_dir'];
$opend = 'thumbnail_'.$dir;
@$opend_result = mkdir ($opend , 0777);
if ($opend_result)
{
$result = opendir($dir);
while ($fn = readdir($result))
{
if ($fn != "." AND $fn != ".." AND !is_dir($fn) AND stristr($fn,'jpg') )
{
// Resize Photo
//echo ($fn."<br>");
$size = getimagesize($dir."/".$fn);
//echo($size[0]." ".$size[1]."<br>");
if ($size[0] <= $width)
{
//copy
$copyfile = $opend."/".$fn;
$original_file =$dir."/".$fn;
copy($original_file , $copyfile);
}
else
{
$factor = $size[0] / $width;
$new_length = intval($size[1] / $factor);
$src_img = imagecreatefromjpeg($dir."/".$fn);
$dst_img = imagecreatetruecolor($width,$new_length);
$src_width=imagesx($src_img);
$src_height=imagesy($src_img);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $new_length, $src_width, $src_height);
imagejpeg($dst_img, $opend."/".$fn, $quality);
imagedestroy($src_img);
imagedestroy($dst_img);
}
}
}
closedir($result);
echo("<br><br><b>Done!</b><br>");
}
}
?>
I tried deleting the files both through ftp and cpanel. I'm really stumped on this one...help!