...

View Full Version : Mapping a folder?



SDP2006
11-27-2003, 06:57 PM
I have a folder /filesys

I want to make a map (directory) of all the files in the folder filesys.

I want the map to show each file and link to each file so that you can view them. How might I do this?

Thanks

SDP2006
11-28-2003, 02:09 PM
Anyone? :D

Nightfire
11-28-2003, 02:16 PM
You just confuse me lol

Are you wanting mapping or a script to show all files in a directory?

SDP2006
11-28-2003, 02:41 PM
Sorry, I want to show all files in a directory and the files linked to their respective files. So if it shows up info.php i want it linked to info.php

Thanks,

Stevie

Nightfire
11-28-2003, 03:15 PM
http://www.hotscripts.com/Detailed/20231.html
http://www.hotscripts.com/Detailed/15298.html

And more...

http://www.hotscripts.com/PHP/Scripts_and_Programs/File_Manipulation/File_Management/

SDP2006
11-28-2003, 03:28 PM
Thanks a lot for your help, but I kinda wanted to learn how to make one by myself? Would someone mind giving me a lesson on how to do it? It would be really appreciated.

Thanks for the continued help.

Nightfire
11-28-2003, 04:26 PM
Not much to it really. Here's some links for the stuff you'll need to use:

http://www.php.net/manual/en/function.opendir.php
http://www.php.net/manual/en/function.readdir.php
http://www.php.net/manual/en/function.closedir.php
http://www.php.net/manual/en/function.rewinddir.php

SDP2006
11-28-2003, 05:13 PM
Thanks, I'll have to try it this evening.

raf
12-02-2003, 07:30 PM
Just in case that didn't satify your hunger

http://www.phpclasses.org/browse.html/package/1376.html

SDP2006
12-14-2003, 09:12 PM
Okay, here is what I have


<?php
$dir = "/usr/local/psa/home/vhosts/net-riches.com/httpdocs/filesys/";

if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false){
if(preg_match("/php/", $file)){
print "<img src=\"webscript.gif\">";
print " <a href='http://www.net-riches.com/filesys/$file'>$file</a>";
print "<br>";
}
if(preg_match("/html/", $file)){
print "<img src=\"webpage.gif\">";
print " <a href='http://www.net-riches.com/filesys/$file'>$file</a>";
print "<br>";
}
if(preg_match("/gif/", $file)){
print "<img src=\"image.gif\">";
print " <a href='http://www.net-riches.com/filesys/$file'>$file</a>";
print "<br>";
}
}
closedir($dh);
}
}
?>

It works, and satisfies my needs, but I want the files to be in alphabetical order. Anyone know How I might do that?

Thanks

SDP2006
12-19-2003, 02:39 AM
Anyone?

firepages
12-19-2003, 10:24 AM
if you have php>=4.3.0 , use glob();




<?
$directory = 'e:\phpdev\www' ;
chdir( $directory ) ;
$yaks = glob( '*' ) ;
natcasesort( $yaks ) ;

foreach( $yaks as $y ){
$str .= '<a href="' . $y . '">' . $y . '</a><br />' ;
}

echo $str ;
?>



you can simulate glob() on *NIX if you have an older version ...



<?
if( phpversion() < '4.3.0' ) {
function glob($pattern){
exec( 'ls | grep '.$pattern , $yaks );
foreach($yaks as $v){
$rets[] = $v ;
}
return $v;
}
}
?>


you may be able to do something similar on windows with 'find' but I never tried.

SDP2006
12-19-2003, 09:13 PM
Thanks for the reply. I'm a little confused. Can you show me using the code in my previous post?

Appreciate It!

Stevie

firepages
12-20-2003, 01:37 AM
...not really as your posted code just prints stuff as it finds it.
to be able to sort the data in anyway you need to be loading the results of your search into arrays which can then be sorted using PHP's built in functions

..one way..


<?php
$dir = "/usr/local/psa/home/vhosts/net-riches.com/httpdocs/filesys/";
if (is_dir($dir)) {
if ( $dh = opendir( $dir ) ) {
while ( ($file = readdir( $dh )) !== false){
/*
one of a myriad of ways of loading into an array .. NOT the best but hopefully obvious
this is simplistic so find a better way
*/
switch( substr( $file ,-4) ){
case('.php'): $php[] = $file ;break;
case('html'): $html[] = $file ;break;
case('.gif'): $gif[] = $file ;break;
default:$other[] = $file ;
}

}
closedir($dh);
}
}
/* this sorts the php array in the way a human might want to read it */
/* but also see sort() asort() etc */
natcasesort( $php ) ;

/*test it*/
print_r( $php ); print_r( $other ) ;//etc



ok now all that did was load data into arrays , you still have to display but a simple ..



<?
foreach( $php as $y ){
$str .= '<a href="' . $y . '">' . $y . '</a><br />' ;
}
echo $str;
?>


would suffice;

still check if your system has glob() available as it is so much cleaner than opendir and friends.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum