Files showing up in terminal run, not in browser

I'm trying to list the files in a directory, but only the HTML portion of the page shows up in my browser. When I run the page through the PHP terminal interpreter, all the files are listed with the proper HTML tags.

files.php:

<html><head><title>Title</title></head>

<body>

<?php
   $currentdir = '/home/tim/Documents/Web/';
   $dir = opendir($currentdir);
   echo '<ul>';
   while ($file = readdir($dir)){
      echo "<li>$file</li>";
   }
?>

</body>
</html>

Answers


If your webserver does parse PHP files, I would suggest putting error_reporting(E_ALL); at the beginning of your script. That will force PHP to spit out any error which may have resulted from path/permission problems, thereby helping you to debug the problem.


Need Your Help

Secure password storage

php security encryption passwords password-protection

I'm developing a web service where users must login. I will store user data in an SQL database and input/output via PHP. But I don't want to store it openly. How do I encrypt the passwords in PHP s...

.Net Unity Object instance issues

asp.net-mvc-2 dependency-injection inversion-of-control enterprise-library unity-container

I really stuck trying to get unity to work for a c# project I'm working on.

jQuery animate only one item (div) on hover (img)

javascript jquery animation jquery-animate

The situation is to make jQuery animating only one element when another one is hovered. Now I get all the items animating when hover action begins.