/    Sign up×
Community /Pin to ProfileBookmark

listing files and directories

ummm, I was wondering if it was possible, and if so how, could use php to automatically list all the files AND subdirectories of a specific directory. Sorta like a php generated index.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@PhenomenaauthorSep 18.2007 — ok sorry for double post, I guess you can't edit your posts here >_<

Anyways I did some looking around and I found about the readdir() function so now I have a page that lists all the directories, and creates a link to them, but instead of having to create a seperate page for each sub directory to read the files how owuld I go about setting it up so it was like...

www.mysite.com/files.php?pictures

when you clicked the picture link generated by the readdir()

lol sorry if this is confusing ?
Copy linkTweet thisAlerts:
@rootSep 18.2007 — IF its any help, this is what I used in a small routine to get the listing of a directory for a web page that I then later expanded to filter by type of file but the core listing of a directroy is this[code=php]<?php
$ver = phpversion();
if( ($v=substr($ver,0,strpos($ver, '.',1)))=="4" ){ // php4
$directory_current = getcwd();
$files_in_current = array();
// read the local directory
$d = dir($directory_current);
while (false !== ($entry = $d->read())){
array_push($files_in_current,$entry);
}
$d->close();
}else{//use php 5
// get current directory
$directory_current = getcwd();
// get the files in that current directory
$files_in_current = scandir($directory_current);
}[/code]
×

Success!

Help @Phenomena 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.20,
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,
)...