At 3:52 PM +0200 5/21/06, Alain Roger wrote:
Hi,
i have 1 folder, in this folder sometime a file can be sometimes not...
1. i would like to detect if the folder contains a file or not.
only 1 file can be in this folder but i do not know the name of this file,
and the extension should be xls.
when this file exists, i want to display the contents of this file to my web
site, how can i do it ?
2. could you advise me on some good tutorial PHP+Excel ?
thanks a lot,
Alain:
I know you asked for a reference, but you might try this.
Replace "tmp" with path/to/your/folder.
The routine will look for files in the indicated folder. If there are
no files present, then nothing happens -- however, if there are any
files present, then it will fill the file_array with their names.
From that, it will look at the files within that array and select out
only those with the proper suffixes and fill the html array. Then it
will read in from the html array and list the contents of those files
to your web page.
This should do what you want.
<?php
$path = "tmp";
if ($handle = opendir($path))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$file_array[] = $file;
if(eregi("(\.xml|\.html|\.htm|\.php|\.txt)", $file))
{
$html[] = $file;
}
}
}
closedir($handle);
}
if (isset($file_array))
{
echo ("<br/>---- all files in dir");
echo ("<pre>");
print_r($file_array);
echo("</pre>");
echo ("<br/>---- selected files in dir");
echo ("<pre>");
print_r($html);
echo("</pre>");
if($html != null)
{
sort($html);
foreach($html as $html => $value)
{
$filename = $path . "/" . $value;
$filesize = filesize($filename);
$file = fopen( $filename, "r" );
$text = fread( $file, $filesize );
fclose( $file );
echo( "<br/>File read: $filename<br/> ");
echo( "File Size: $filesize bytes<br/>" );
echo( "File Content:$text<br/>" );
}
}
}
else
{
echo ("<br/>---- nothing to read");
}
?>
hth's
tedd
--
------------------------------------------------------------------------------------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php