Page 1 of 1
No brainer?
Posted: Sat Sep 11, 2004 9:22 am
by neophyte
I figure I'm doing something reallly dumb. This is part of a simple directory class I'm writing. $files returns a populated array when the ''is_file" test is absent. print_r($files); displays what I'd expect it to. When I add "if (is_file($file)){" print_r() print's nothing..... I figure I'm doing something very n00b. Suggestions?
Code: Select all
if ($type =="file"){
while (($file = readdir($this->dh)) !== false) {
if ( $file != "." && $file != ".." ){
if (is_file($file)){
$files[] = $file;
}
}else{
$junk[] =$file;
}
Posted: Sat Sep 11, 2004 9:39 am
by hawleyjr
You have some missing brackets. Try this:
Code: Select all
<?php
if ($type =="file"){
while (($file = readdir($this->dh)) !== false) {
if ( $file != "." && $file != ".." ){
if (is_file($file)){
$files[] = $file;
}
}else{
$junk[] =$file;
}// ene elese
}// end loop
}
?>
Sorry about that...
Posted: Sat Sep 11, 2004 9:52 am
by neophyte
Actually here's the class I'm working on. It's not much.
Code: Select all
class dynamicdir {
var $directory;
var $path;
var $dh;
var $readable;
var $writable;
var $executable;
function dynamicdir($path, $directory){
$this->path = $path;
$this->directory = $directory;
if (is_dir($this->path.$this->directory)) {
$this->dh = opendir($this->path.$this->directory);
}
if ($this->dh){
return $this->dh;
} else {
}
}//end constructor function
function directorylist($exclude, $type){
if ($type =="file"){
while (($file = readdir($this->dh)) !== false) {
if ( $file != "." && $file != ".." ){
if (is_file($file)){
$files[] = $file;
}
}else{
$junk[] =$file;
}// ene elese
}// end loop
} else if ($type == "dir"){
while (($file = readdir($this->dh)) !== false) {
if ($file != "." && $file != ".." && !is_file($file)){
$files[] = $file;
}
}
} else{
}
return $files;
I'm working on the directorylist().
Here's how I've created the object....
Code: Select all
$dir = new dynamicdir ("/some/absolute/path/","Some_directory");
$files = $dir -> directorylist("", "file");
print_r($files);
the print_r shows a populated array for $files when the is_file or is_dir test is not applied. When I add the is_file/is_dir test print_r does not show anything.
I figure I'm doing something wrong here but I'm not sure what...
Posted: Sat Sep 11, 2004 10:54 am
by m3mn0n
Suggestion: comment your code more.
Posted: Sat Sep 11, 2004 11:36 am
by feyd
neophyte, please please use the
Code: Select all
tags ...
$file in the function is strictly the filename, not the path.. is_file requires the path.
Sorry
Posted: Sat Sep 11, 2004 12:16 pm
by neophyte
Doh... I knew it was somethin simple. Right on, for now on --
!
Code: Select all
<?php echo "Thanks feyd, Sami, and hawleyjr"
?>