473,799 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 getDirectoryLis t($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;
}
}

}

getDirectoryLis t();

?>

Here's what I get:

directory:.
directory:..
dunno:delete.pn g
dunno:rename.pn g
dunno:view.png
directory:image s
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 2585
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 getDirectoryLis t($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;
}
}

}

getDirectoryLis t();

?>

Here's what I get:

directory:.
directory:..
dunno:delete.pn g
dunno:rename.pn g
dunno:view.png
directory:image s
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
4950
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
3818
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 4.06. However, today I'm trying to run this software on a new server (RH Linux 9, PHP 4.2.3) and the directory is failing the is_dir() test. The error message that I have in my code is printing out this error: In getListOfAnyDirectory(), we...
5
4000
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: chdir(): No such file or directory (errno 2) The same script works at my personal host, thats the part that bothers me. The host here at work is running PHP 4.3.8. Any suggestions about how to get this to work? or maybe another function that does...
3
1845
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 xerces downloaded and compiled), however, I'm getting quite a few compile errors. I downloaded and compiled xerces 2.6.0 and I downloaded xalan 1.9.0.
1
1690
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 something like: mkdir("/home/httpd/vhosts/website.com/httpdocs/dev1/test_folder1", 0777); What's the problem?
30
7713
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 target directory (where the backup copies will be kept, on another drive). I can successfully test whether the target directory exists or not using findfirst(), but if it doesn't, I wanted to create it using mkdir(), but it doesn't like the path...
3
1695
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 = "/home/fouad/testing"; if(mkdir($path,700,TRUE)) {print "success."; }else {print "failure.";} ?>
1
2410
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 the scripts is a variable containing the path to the target directory. The scripts are located here: http://ionline.dk/test/test1.php
1
1810
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); if(!(is_dir(realpath("/uploads")))) { mkdir("uploads/".$var2."/", 0777); }
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10031
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.