• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

list files to php

How can I get "list.php" to list the files from a folder. i.e. d:\documents\?
I just want a simple list so that my students can view the projects archieve etc..

Please help!
0
Virik
Asked:
Virik
1 Solution
 
carchitectCommented:
<?
$d = dir("password"); ///directory path
echo "Handle: ".$d->handle."<br>\n";
echo "Path: ".$d->path."<br>\n";
while (false !== ($entry = $d->read())) {
    echo $entry."<br>\n";
}
$d->close();
?>


regards
0
 
VirikAuthor Commented:
Thanks!

But, I must be stupid or something =)
Where in the code do I type "D:\documents", and what
else must I change?
0
 
carchitectCommented:
hi i have written to change directory path sir...

<?
$d = dir("D:\documents"); ///directory path
echo "Handle: ".$d->handle."<br>\n";
echo "Path: ".$d->path."<br>\n";
while (false !== ($entry = $d->read())) {
   echo $entry."<br>\n";
}
$d->close();
?>



0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
VGRCommented:
what a C style !!! :D :D

Solution 1 : (whatever, not sorted, or sorted by default by the OS)
$d = dir("./s/");
while($entry=$d->read()) {
  if (($entry<>'.') and ($entry<>'..') and ($entry<>'')) {
    // do your stuff on the file of name = $entry
  } // if affichage
} // while
$d->close();

Solution 2 : (Windows, sorted by alphabetic name)
$directory2=str_replace('/','\\',$directory);
$d = @popen ("dir /ON /B $directory2", "r"); //
while (!feof ($d)) {
  $buffer = fgets($d, 4096);
  $entry=chop($buffer);
  if (($entry<>'.') and ($entry<>'..') and ($entry<>'')) {
    //do your stuff on file $entry
  } // if affichage
} // while
$toto=@pclose($d);
0
 
hexabrCommented:
a simple

$vars = ´ls *.ext´ wouldnt sufice?
0
 
VGRCommented:
exec("ls ..."); yes, a simple "ls" no ;-)

dir() or popen("dir") (windows) are the same as exec("dir")
0
 
snoyes_jwCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: carchitect {http:#8098722}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

snoyes_jw
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now