Forum Moderators: coopster
<?php
$count = 0;
if ($handle = opendir('receipes'))
{
while (false!== ($file = readdir($handle)))
{
if ($file!= "." && $file!= "..")
{
//read file line by line into array
$lines = file("receipes/$file", "r");
echo "<td>";
echo "<font class=\"subtitle\"><a href=\"print.php3?receipe=$file\">$lines[0]</a></font>";
echo "<br />";
echo "<font class=\"maintext\">$lines[1]</font>";
echo "</td>";
$count = $count +1;
if ($count == 3)
{
echo "</tr><tr>";
$count = 0;
}
}
}
closedir($handle);
}
?>
Yes, if you intend to read the directory using the PHP readdir() [php.net] function.
You could load the files into an array first, then use a foreach to process if the array is not empty...
$files = array();
if ($handle = @opendir($dir)) {
while (false!== ($filename = readdir($handle))) {
$files[] = $filename;
}
closedir($handle);
if (!$files) {
print "No files in directory";
} else {
natcasesort [php.net]($files); // <-- Want them sorted in natural case order?
foreach ($files as $filename) {
// Eliminates the ., .., as well as any .htaccess files from being listed:
if (is_file($dir.$filename) and substr($filename, 0 , 1)!= '.') {
// your processing code here...
}
}
}
unset($files);
}
I have one question:
can I use such a script for checking a specific folders content? I want the script to send me an email with the filename(s) and a direct link to the file(s).
Any idea?
/Holger