473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 2569
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: bart | last post by:
i run 4.3.4 but is_dir doesn't work always. when i put a counter in a readdir loop, it returns the number 5 that is; .. ...
4
by: lawrence | last post by:
In the function below, before I open the directory I first test to make sure the address I have is, in fact, a directory. This function was working fine on one web server running FreeBSD and PHP...
5
by: Nicholas Geraldi | last post by:
I have a script that uses the chdir() function. I know the script works ( works perfectly on my host ), but when I put the script on my server here at work I get the following error. Warning:...
3
by: Avalon1178 | last post by:
Hi, I recently downloaded the xalan-c source code in http://mirrors.ccs.neu.edu/Apache/dist/xml/xalan-c I followed the instructions from the apache site on how to build it (I already have...
1
by: joelbyrd | last post by:
I'm trying to do a mkdir(), but I'm getting permission denied error, even though I've set the mode to 0777: mkdir($full_path, 0777). I also couldn't do a chmod successfully. The code is...
30
by: MikeC | last post by:
Good People, I'm writing a backup utility that uses a chdir() to go into the source directory (in which the files reside that I want to back up), so I don't want to use chdir() to get into the...
3
by: fouadk | last post by:
hi everyone.... i am trying to create a folder in my home directory but that ain't working due to permission restriction my code looks like the following: <?php $path =...
1
by: ndlarsen | last post by:
Hello. I have a minor issue with is_dir(). When running two almost identical scripts from two different directories with same target directory I get different output. The only difference between...
1
by: softy1 | last post by:
I am having problem in chmod permission settings Here is script <?php $uploaddir = $_POST; $dirsplit = $uploaddir; list($var1, $var2) = explode('/', $dirsplit);...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.