/    Sign up×
Community /Pin to ProfileBookmark

how to list folders in my web address

hello,
to share some files with friends, i created a directory under my website and uploaded several folders under that directory. each folder contain the files i want to share.

but when i type the path to the main directory, it says 403 forbidden. how can i automatically list folders under the main directory? and i want them to be clickable so that once they click on the folder name they should be able to see the files under the folder that they clicked.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 15.2012 — One option is to configure your web server to allow directory listings, or you can create a default page (e.g. index.php) to display the directory contents, making use of the glob() function, perhaps.
Copy linkTweet thisAlerts:
@parkerfrank32Oct 15.2012 — OK i get the code that let me list all the folders and subfolders with files inside:

<?php

$dir = scandir("./");

echo "<ul>";

foreach($dir as $v1){

if($v1 != "." && $v1 != ".."){

if(is_file("./".$v1)){

echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."<br />";

}

//// si es un directorio se lo recorre ///////

if(is_dir("./".$v1)){

echo "<li><strong>". $v1 ."</strong>";

$dir2 = scandir("./".$v1);

echo "<ul>";

foreach($dir2 as $v2){

if($v2 != "." && $v2 != ".."){

if(is_file("./".$v1."/".$v2)){

echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."/". $v2 ."<br />";

}

//// si es un nuevo directorio se lo recorre ///////

if(is_dir("./".$v1."/".$v2)){

echo "<li><strong>". $v2 ."</strong>";

$dir3 = scandir("./".$v1."/".$v2);

echo "<ul>";

foreach($dir3 as $v3){

if($v3 != "." && $v3 != ".."){

if(is_file("./".$v1."/".$v2."/".$v3)){

echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."/". $v2 ."/". $v3 ."<br />";

}

//// si es un nuevo directorio se lo recorre ///////

if(is_dir("./".$v1."/".$v2."/".$v3)){

echo "<li><strong>". $v3 ."</strong>";

$dir4 = scandir("./".$v1."/".$v2."/".$v3);

echo "<ul>";

foreach($dir4 as $v4){

if($v4 != "." && $v4 != ".."){

if(is_file("./".$v1."/".$v2."/".$v3."/".$v4)){

echo "http://". $_SERVER['SERVER_NAME'] ."/". $v1 ."/". $v2 ."/". $v3 ."/". $v4 ."<br />";

}

//// si es un nuevo directorio se lo recorre ///////

if(is_dir("./".$v1."/".$v2."/".$v3."/".$v4)){

echo "<li><strong>". $v4 ."</strong>";

}

}

}

echo "</ul>";

}

}

}

echo "</ul>";

}

}

}

echo "</ul>";

}

}

}

echo "</ul>";

?>
Copy linkTweet thisAlerts:
@ZABIOct 15.2012 — also you can search directory index script, there are lots of useful scripts having good features for sharing files,
×

Success!

Help @ketanco spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...