I trying to display the contents of every file in the directory called "news." All the files in news are .txt files. This is my code that I got so far. The problem is at it is reading the directory that index.php is in(www/u/username/htdocs/news) not the directory news. any help would appecatied.
$handle= "/www/u/username/htdocs/news";
if ($handle = opendir('.'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
require($file);
echo "
" ;
echo "$file\n";
echo"
";
}
}
closedir($handle);
}
echo "finsh\n";
?>
Any help would be appecatied.
Aaron
newbie with php
Moderator: General Moderators
ok I got that problem solved, but got another problem
ok I want to display the contents of the file and it ain't doing it. It is displaying the files names right. Any help would be appecatied.
<?php
if ($handle = opendir('./news/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
readfile($file);
echo "\n"
echo "$file\n";
echo"\n"
}
}
closedir($handle);
}
echo "f\n";
?>
<?php
if ($handle = opendir('./news/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
readfile($file);
echo "\n"
echo "$file\n";
echo"\n"
}
}
closedir($handle);
}
echo "f\n";
?>
having problem with fopen()
I'm opening the file, saving the file to a string then printing the string. Well when I echo the string (echo "$data"; ) it doesn't work. here is the code
$fp = fopen($file, "r");
$data = fread($fp, 1024*1024);
fclose($fp);
echo "$data";
any help would we appeacited.
Thanks
Aaron
$fp = fopen($file, "r");
$data = fread($fp, 1024*1024);
fclose($fp);
echo "$data";
any help would we appeacited.
Thanks
Aaron
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
http://www.php.net/manual/en/function.f ... ntents.php
Good luck.
The manual is very useful.file_get_contents -- Reads entire file into a string
Good luck.
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
Code: Select all
string file_get_contents ( string filename ї, bool use_include_path ї, resource context ї, int offset]]])So this would be sufficient:
Code: Select all
<?php
$strFileContent = file_get_contents($strFileName);
?>Thanks for the help problem solved.
Thanks for the help problem solved you guys are awesome