Hi. I got this script from the internet which serves my purpose of just displaying the content in my directory so that people can download it. I just have one query. Code: function printFiles($path,$level) { if (is_dir($path)) { if ($dh = opendir($path)) { $spaces = str_repeat( ' ',($level*10));//spaces indent while (($file = readdir($dh)) !== false) { $Filename=$path.$file; $pos=strpos($file, "."); if ($pos!=0||$pos===false) {//no hidden files if (is_dir($Filename)) {//directory echo $spaces."<b>". $file."</b><br/>"; printFiles($Filename."/",$level+1);//recursive! } else { echo "$spaces<a href='$file'>".$file."</a><br/>";//normal files } } } closedir($dh); echo "<br>"; } } } printFiles($_SERVER["DOCUMENT_ROOT"]."/temp_folder/",0);//start! The script uses only one "=" sign in the if statement. It doesnt work if there are two.
Display directory content using PHP
2
Hi. I got this script from the internet which serves my purpose of just displaying the content in my directory so that people can download it. I just have one query.
The script uses only one "=" sign in the if statement. It doesnt work if there are two.
How is this possible? And also how can I modify this code to display the file size?
Code:
function printFiles($path,$level)
{
if (is_dir($path))
{
{
$spaces = str_repeat( ' ',($level*10));//spaces indent
while (($file = readdir($dh)) !== false)
{
$Filename=$path.$file;
$pos=strpos($file, ".");
if ($pos!=0||$pos===false)
{//no hidden files
if (is_dir($Filename))
{//directory
echo $spaces."<b>". $file."</b><br/>";
printFiles($Filename."/",$level+1);//recursive!
}
else
{
echo "$spaces<a href='$file'>".$file."</a><br/>";//normal files
}
}
}
closedir($dh);
echo "<br>";
}
}
}
printFiles($_SERVER["DOCUMENT_ROOT"]."/temp_folder/",0);//start! How is this possible? And also how can I modify this code to display the file size?
- imarketstuff
- [ 1 ] Thanks
Next Topics on Trending Feed
-
2