Hmmm, the problem with that, is that it is similar to: $dh = opendir($dir);
while (false !== ($filename = readdir($dh))){}, which is what I have been trying to use. The problem that I am having is I see no way to write to a specific dir, only read what is in a specific dir. Granted, I could use fopen, and fwrite, but that only deals with a file.
Here is the code that I was working on to get the program to do what I wanted.
Sorry it is so messy!
<?php
$imagetype="jpg,JPG,jpeg,JPEG,PNG,png";
$currentdir = opendir(".");
while (($file= readdir($currentdir))!==false)
{
$filetype = filetype($file);
if ($filetype == "dir" && $file != ".." )
{
print " <br>filetype:$filetype, ";
print "file:$file<br><br>";
$imagefolder = $file;
$thumbsfolder= $file;
$imagetype = "jpg,JPG,jpeg,JPEG,png,PNG";
if (imagefinder($imagetype,$imagefolder)>=5)
{
$pics=directory($imagefolder,$imagetype);
$phpname="g$file.php";
$pics=ditchtn($pics,"tn");
if ($pics[0]!="")
{
foreach ($pics as $p)
{ createthumb($p,"tn_".$p,150,150,$thumbsfolder); }
phpcreator($pics,"tn_",$phpname,$imagefolder);
}
}
}
}
function imagefinder ($filetype,$imagefolder)
{
$currentdir=opendir($imagefolder);
$files=array();
$filename=array();
$filenumber = 0;
$filetp = explode (",",$filetype);
while (($file=readdir($currentdir))!==false)
{
$filename = explode(".",$file);
if (isset($filename[1]))
{
foreach($filetp as $type)
{
if ($filename[1] == $type)
{
++$filenumber;
}
}
}
}
return $filenumber;
}
/*
Function ditchtn($arr,$thumbname)
filters out thumbnails
*/
function ditchtn($arr,$thumbname)
{
foreach ($arr as $item)
{
if (!preg_match("/".$thumbname."/",$item))
{$tmparr[]=$item;}
}
return $tmparr;
}
/
Function createthumb($name,$filename,$new_w,$new_h)
creates a resized image
variables:
$name Original filename
$filename Filename of the resized image
$new_w width of resized image
$new_h height of resized image
/
function createthumb($name,$filename,$new_w,$new_h,$thumbsfolder)
{
$system=explode(".",$name);
$name = "./$thumbsfolder/$name";
if (preg_match("/|JPG|JPEG|jpg|jpeg/",$system[1]))
{
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/png|PNG/",$system[1]))
{$src_img=imagecreatefrompng($name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
/
Function directory($directory,$filters)
reads the content of $directory, takes the files that apply to $filter
and returns an array of the filenames.
You can specify which files to read, for example
$files = directory(".","jpg,gif");
gets all jpg and gif files in this directory.
$files = directory(".","all");
gets all files.
/
function directory($dir,$filters)
{
$handle=opendir($dir);
$files=array();
$filters=explode(",",$filters);
while (($file = readdir($handle))!==false)
{
for ($f=0;$f<sizeof($filters);$f++):
$system=explode(".",$file);
if (isset($system[1]))
{
if ($system[1] == $filters[$f])
$files[] = $file;
}
endfor;
}
closedir($handle);
return $files;
}
function phpcreator($pics,$thumbname,$phpname,$imagefolder)
{
foreach($pics as $pic)
{
$ofile=fopen("$phpname","a");
$newcontent= "<a href=\"$imagefolder/$pic\"><img src=\"$imagefolder/$thumbname$pic\"></a>\r\n";
fwrite($ofile, $newcontent);
fclose($ofile);
}
}
?>