471,071 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

Problems with mkdir() and is_dir()

I'm creating a script for our website which will function as something
of a docment manager. The backend features an option to create a new
directory in the uploads subdirectory. The problem is, once I've used
mkdir() to create this file, when I later run is_dir() on the filename,
I get 'false'. Even worse, if I run is_file() on the new directories,
I get false as well. The same thing seems to be happening to files I
submit via the script, though that is less of a worry (I never actually
*need* to run this test). Here is a copy of a smaller script I threw
together trying to figure out what exactly was going on:

<?php

function getDirectoryList($root="(this is where the directory I'm
working in goes)"){

clearstatcache();

$dir = dir($root);

while($file = readdir($dir->handle)){
if(is_dir($file)){
echo "<br />directory:" . $file;
} elseif(is_file($file)){
echo "<br />file:" . $file;
} else {
echo "<br />dunno:" . $file;
}
}

}

getDirectoryList();

?>

Here's what I get:

directory:.
directory:..
dunno:delete.png
dunno:rename.png
dunno:view.png
directory:images
dunno:PDFs
dunno:somecrap

The last two, PDFs and somecrap, are folders created with mkdir(). The
..pngs are files uploaded via a PHP script. Is this some kind of fluke
with PHP, or is there anything I can do? Thank you all in advance for
your help.

Peace,
Juby

Feb 23 '06 #1
2 2459
Juby wrote:
I'm creating a script for our website which will function as something
of a docment manager. The backend features an option to create a new
directory in the uploads subdirectory. The problem is, once I've used
mkdir() to create this file, when I later run is_dir() on the filename,
I get 'false'. Even worse, if I run is_file() on the new directories,
I get false as well. The same thing seems to be happening to files I
submit via the script, though that is less of a worry (I never actually
*need* to run this test). Here is a copy of a smaller script I threw
together trying to figure out what exactly was going on:

<?php

function getDirectoryList($root="(this is where the directory I'm
working in goes)"){

clearstatcache();

$dir = dir($root);

while($file = readdir($dir->handle)){
if(is_dir($file)){
echo "<br />directory:" . $file;
} elseif(is_file($file)){
echo "<br />file:" . $file;
} else {
echo "<br />dunno:" . $file;
}
}

}

getDirectoryList();

?>

Here's what I get:

directory:.
directory:..
dunno:delete.png
dunno:rename.png
dunno:view.png
directory:images
dunno:PDFs
dunno:somecrap

The last two, PDFs and somecrap, are folders created with mkdir(). The
.pngs are files uploaded via a PHP script. Is this some kind of fluke
with PHP, or is there anything I can do? Thank you all in advance for
your help.

Peace,
Juby

Hi Juby,

Where is the directory excactly?
How does the path look?
Is it some networkmapped directory, samba, etc?

Maybe you forgot to use \ before / ?

If you provide that info, maybe we can find the problem.

Regards,
Erwin Moller
Feb 24 '06 #2
Erwin,

Thanks for your help, but I actually figured it out. It turned out
that the script was looking in its own directory for these files, not
the directory I was having it search. I just prepended the $root
string onto the $file variable, and everything worked smooth as silk.
Hopefully someone else runs across this and figures out their own
stupidity before making a public fool of themselves, like I did! :-)

Peace,
Andrew Juby

Feb 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by bart | last post: by
4 posts views Thread by lawrence | last post: by
5 posts views Thread by Nicholas Geraldi | last post: by
3 posts views Thread by Avalon1178 | last post: by
1 post views Thread by joelbyrd | last post: by
30 posts views Thread by MikeC | last post: by
3 posts views Thread by fouadk | last post: by
1 post views Thread by ndlarsen | last post: by
1 post views Thread by softy1 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.