Help plz!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benjaminbga
Forum Newbie
Posts: 2
Joined: Sat Dec 03, 2011 1:23 am

Help plz!

Post 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?
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: Help plz!

Post by internet-solution »

what is the extension of your php filename?
benjaminbga
Forum Newbie
Posts: 2
Joined: Sat Dec 03, 2011 1:23 am

Re: Help plz!

Post by benjaminbga »

.html, it is inserted in the middle of the index page. Im new at this, is that the problem?
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: Help plz!

Post 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.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Help plz!

Post by phphelpme »

if you coding in PHP then just use php filename. That would solve many issues and needless additional configurations on your server. :)
Post Reply