Page 1 of 1

Help plz!

Posted: Sat Dec 03, 2011 1:30 am
by benjaminbga
I been trying for hours to make this code work but everytime I use a ">" inside the code it stops runing.

Code: Select all

<?php


							  function getDirectoryList ($directory) 
							  {
							
							    // create an array to hold directory list
							    $results = array();
							
							    // create a handler for the directory
							    $handler = opendir($directory);
						
														
							    // open directory and walk through the filenames
							    while ($file = readdir($handler)) {
							
							      // if file isn't this directory or its parent, add it to the results
							      if ($file != "." && $file != "..") {
							      echo "<p>".$filename."</p>";
							      }
							
							    }
							
							    // tidy up: close the handler
							    closedir($handler);							
							  }

							getDirectoryList('/images/display');

							
							?>
When I run the code this is what i get in the browser instead of the files in the directory:

".$directory."
"; // open directory and walk through the filenames while ($file = readdir($handler)) { // if file isn't this directory or its parent, add it to the results if ($file != "." && $file != "..") { echo "hola"; } } // tidy up: close the handler closedir($handler); // done! return $results; } getDirectoryList('/images/display'); ?>

any idea what is wrong?

Re: Help plz!

Posted: Sat Dec 03, 2011 7:10 pm
by internet-solution
what is the extension of your php filename?

Re: Help plz!

Posted: Sat Dec 03, 2011 9:21 pm
by benjaminbga
.html, it is inserted in the middle of the index page. Im new at this, is that the problem?

Re: Help plz!

Posted: Sun Dec 04, 2011 1:45 pm
by internet-solution
yes. By default webservers only parse php codes in files with .php extension.

If you want to add php codes in html, you will have to change your webserver configuration.

Re: Help plz!

Posted: Fri Dec 09, 2011 3:50 am
by phphelpme
if you coding in PHP then just use php filename. That would solve many issues and needless additional configurations on your server. :)