/    Sign up×
Community /Pin to ProfileBookmark

Get files in a folder.

I am stumped, I would like to have a code on my site that will make a list of all the files on a users website. Basically, I want the user to come and copy this code to a file on their website, and then the code will be placed in the root folder of their site. When the code runs, I would like it to grab every file textual web file they have created, such as some of these formats:
html,htm,php,shtml,asp,dhtml,txt

This would also search all subdirectories as well, and save those URL’s too.

The EXACT URL of each file will then be saved to a txt file that will be saved in their root directory.

I would like it to ignore all image files, exe files, and anything that would not contain textual content that can be displayed on the web.

anyone know of a way to do this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehMay 29.2007 — [code=php]<?php

function kids($dir, $allowed_extensions)
{
if ($handle = opendir($dir))
{
$output = array();
while (false !== ($item = readdir($handle)))
{
if (is_dir($dir.'/'.$item) and $item != "." and $item != "..")
{
$output = array_merge($output, kids($dir.'/'.$item, $allowed_extensions));
}
elseif(is_file($dir.'/'.$item) and
in_array(preg_replace('/^.*((?<=.)[^.]+)$/', '$1', $item), $allowed_extensions))
{
$output[] = $dir.'/'.$item;
}
}
closedir($handle);
return $output;
}
return false;
}

print_r(kids('.', array('html','htm','php','shtml','asp','dhtml','txt')));

?>[/code]
Copy linkTweet thisAlerts:
@The_Little_GuyauthorMay 29.2007 — That worked perfect, but I can't remember what the $_SERVER variable is that will display the domain URL Ex:

http://google.com, http://myspace.com, http://youtube.com etc.
Copy linkTweet thisAlerts:
@bokehMay 29.2007 — HTTP_HOST to get the domain.
×

Success!

Help @The_Little_Guy 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...