Re: open directory and read the file
| From: | Daniel Crespo | Date: | Wed, 24 Dec 2003 07:10:36 +0000 |
| Subject: | Re: open directory and read the file | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-22424@lists.php.net to get a copy of this message | ||
I think you have the problem in:
$handle_file = fopen ($find_file, "r");
while (!feof ($handle_file)){
$buffer = fgets($handle_file, 4096);
echo "$buffer<br>";
}
Right? Well, I think the next code could help you:
<? $cats = file("test.txt");
for($i=0; $i<count($cats); $i++) {
echo $cats[$i]."<br>";
}
?>
This prints each line of the text file. I hope it helps you.
"Idur" <bakpia_lumpia@yahoo.com> escribió en el mensaje
news:20031223174226.80460.qmail@web40507.mail.yahoo.com...
> Hi there,
>
> I want read a directory and open a file inside the directory, for example
directory data contains of file:
> Computername.txt
> IPaddress.txt
> status.txt
>
> and i want search a file on the directory and open it, for example i want
search file IPaddress.txt and when file IPaddress.txt found, i want open it,
read and display the contains of the file.
>
> the script that i have is like this :
> <?php
> $find_file="name.txt";
> if ($handle = opendir('C:\apache\htdocs')){
> while (false !== ($file = readdir($handle))){
> if ($file == $find_file){
> echo " file found $file<br>";
>
> // i want to open the file, but i am confuse with the file
handle
> $handle_file = fopen ($find_file, "r");
> while (!feof ($handle_file)){
> $buffer = fgets($handle_file, 4096);
> echo "$buffer<br>";
> }
> }
> }
> closedir($handle);
> }
> ?>
> this script does'nt run correctly i have an error message, "Warning:
Supplied argument is not a valid File-Handle resource in
c:\apache\htdocs\fseek\readdir.php on line 11"
>
> I confuse with the file handle, because is different with opening file
like usually, what should i do...??? does any one can help me...??
>
> Thanx
> idur
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Photos - Get your photo on the big screen in Times Square