Help on Directory Listing

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
tkuan77
Forum Newbie
Posts: 5
Joined: Fri Jul 30, 2010 2:07 am

Help on Directory Listing

Post by tkuan77 »

Hi guys,

I am currently trying to work out a directory drop down list on my website and I want it when the user select from the drop down list, it will POST it to the next page. I am able to get it working on google chrome but not on IE and Fire Fox and have been stuck for a while. The code are as follows:


send.php:

<form action="receive.php" method="post">

<select name="aaa">

<?php

echo "<select name=\"file\">\n";
foreach (new DirectoryIterator('.') as $file) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) {
echo "<option>";
// if the element is a directory add to the file name "(Dir)"
echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename(); //////
echo "</option>\n";
}
}
echo "</select>\n";

?>

</select>

<input type="submit" />

</form>


receive.php:

<?php
$name = $_POST['aaa'];
echo $name
?>


I really hope that someone could help me out here. I am sorry and thank you for the trouble as I am still new to PHP and learning on the go here.

Regards
Jes
rupeshkumar_rj
Forum Newbie
Posts: 5
Joined: Fri Jul 30, 2010 4:00 am

Re: Help on Directory Listing

Post by rupeshkumar_rj »

There are two corrections in your to make it work.

In send.php, remove the <select name="aaa"></select>

In receive.php, change this
$name = $_POST['aaa'];
to
$name = $_POST['file'];

It seems like you are creating a select within a select & there is a confusion there. One select if the html code & the other is created using php.
rupeshkumar_rj
Forum Newbie
Posts: 5
Joined: Fri Jul 30, 2010 4:00 am

Re: Help on Directory Listing

Post by rupeshkumar_rj »

were you able to get the list of drive in the same way. I am looking for a code to get the list of drives on my local.
tkuan77
Forum Newbie
Posts: 5
Joined: Fri Jul 30, 2010 2:07 am

Re: Help on Directory Listing

Post by tkuan77 »

thanks rupeshkumar_rj,

that solved my problem. Sorry I don have the file that you are looking for. I only started using php 3 days back. Maybe your could try posting it on the forum?

Regards
Jes
Post Reply