/    Sign up×
Community /Pin to ProfileBookmark

Permissions problem….

I’m trying to read a directory of files while avoiding files that are not readable.

Here is the code that i have but is not working.

[CODE]
/*{{{ readdir: reads in a directory (non-recursively) optionally testing filenames against a provided regex string */
function readdir($dir,$match = null) {
$files = array();
$file = “”;
$d = dir($dir);
while (false !== ($file = $d->read())) {
if(true == is_readable($file)){
if ($file{0} == ‘.’)
continue;
else if (isset($match) && preg_match($match,$file))
$files[] = $file;
else if (!isset($match))
$files[] = $file;
}
}
$d->close();
sort($files);
return $files;
}/*}}}*/

[/CODE]

Can anyone tell me what i’m doing wrong? To me it seems like the is_readable() is not working correctly…

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyMay 01.2007 — I use this[code=php] <?php
$path = $_SERVER['DOCUMENT_ROOT']."/intranet/staff/files/mac/";
$dls = array();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$dls[] = $file;
}
}
closedir($handle);
}
sort($dls);
$remove = array("_"); //Removes certain chars from file name and replaces them with spaces
foreach($dls as $id => $name){
echo "<li><a href="http://192.168.100.200/intranet/staff/files/mac/$name" target="_blank" title="Filesize:";
if( filesize( $path . $name ) >= 1024 ) {
# Size in kilobytes
echo " " . round( filesize( $path . $name ) / 1024, 1 ) . " KB";
} elseif( filesize( $path . $file ) >= 1048576 ) {
# Size in megabytes
echo " " . round( filesize( $path . $name ) / 1024 / 1024, 1 ) . " MB";
} else {
# Size in bytes
echo " " . filesize( $path . $name ) . " bytes";
}
echo "">".str_replace($remove," ",$name)."</a>";
$ext = explode(".",$name);
$ext = array_reverse($ext);
}
?>
[/code]
×

Success!

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