have writen the following code and need help in determining if the logic is correct ?
I want to open & read a directory, read each file's name and read each line, and write it all to a single tempfile,
then open the tempfile and read add lines/content & place this inside the body of an email,
then move each read file and delete each from original directory, then delete the tempfile.
So my email should look like this:
$file (first file name)
$line (each line)
$line
$line
(space)
$file (next file name)
$line
$line
(space)
$file
$line
$line
<?
$dirname=" ";
$tempfile=" ";
//open directory & read each file
$dh=opendir($dirname);
while ( gettype($file=readdir($dh)) !=boolean )
{
// open $tempfile & write $file name & close
$fp = fopen("$tempfile", "w+");
fwrite($fp, "\n\n$file"); //write filename
// open & read each line in $file
$fp2 = fopen($file, "r") ;
while (! feof( $fp2 ) )
}
$line = fgets( $fp2, 1024 ) ;
// write each $line into $tempfile
fwrite($fp, "$Line");
fclose($fp2);
}
// copy $file to "old" directory & delete $file from $dir
copy("/home/www/$dir/$file.asc", "/home/www/old/$file.asc");
unlink("$dir/$file.asc");
}
fclose($fp);
// open tempfile & read file for inclusion into email body
$fd = fopen($tempfile, "r");
$message = fread($fd, filesize($tempfile));
fclose($fd);
// send the email message
mail("me@emi.net", "my files", $message, "From: My Web Site");
// delete tempfile
unlink("$tempfile");
?>
Many many thanks,
Peter