/    Sign up×
Community /Pin to ProfileBookmark

custom directory listing script in apache/php in shared hosting

As we know that if we have enabled directory listing then all files and folders will be listed if we do not have index.* or default.*

I have used htaccess to auto prepend a php script thinking that it will run instead of the default directory script. but it works only for scripts like php and not for html or other extensions.

So here what i want is i want to do my custom directory listing but i don’t want to put an index.php in all folders with my custom code… whereas i want to autoprepend my custom directory listing script in htaccess but this is not working…

so i want to run my custom script for directory listing

[B]Besides, i am in a shared hosting so i cannot modify config files. htaccess is working.
[/B]

so what is the way to do a custom directory listing?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NoEffinWayFeb 23.2012 — If I am understanding you correctly, this script should be a helpful start:

[code=php]<?
$dir = '.';
if (isset($_GET['path'])){
$dir = $_GET['path'];
}
if ($handle = opendir($dir)) {
echo 'Current Directory: '.$dir;
while (false !== ($entry = readdir($handle))) {
if($entry != '.' && $entry != '..'){
$isfile = explode('.', $entry);
if($dir == '.'){
$href = $entry;
}else{
$href = $dir.$entry;
}
if(count($isfile)==1){
$href = '?path='.$href.'/';
}
echo '<br /><a href="'.$href.'">'.$entry.'</a>';
}
}
}
?>[/code]
Copy linkTweet thisAlerts:
@jayapalchandranauthorFeb 26.2012 — yes... i already did the same with scandir. thank you.
×

Success!

Help @jayapalchandran 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.19,
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,
)...