A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearCheck whether a Directory Exists in PHP - page 1
User InfoPosts
Check whether a Directory Exists in PHP#1
I know, I know, this sounds soo easy. But I can(t seem to find the correct answer on the Internet.

One of the solution I found was to use is_dir.

if(is_dir($dir))
echo (directory exists(;
else
echo (drectory not exist(;


But this is wrong-- All this function does is to check whether the $dir is a directory, it doesn(t check whether the directory exists, or not. In other words if I put:

$rootDir = "C:\\Documents and Settings\\test\\My Documents\\Image Directory\\Me Dog\\";


then the function will return a true, even though you can find no such directory on your web server.

Any ideas?

posted date: 2009-04-13 23:45:00


Re: Check whether a Directory Exists in PHP#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-13 23:45:01


Re: Check whether a Directory Exists in PHP#3
Should work correctly. From is_dir() documentation:Returns TRUE if the filename exists and is a directory, FALSE otherwise.Well, anyway if it doesn(t try this:if(file_exists($dir) && is_dir($dir))BTW. results of these functions are cached in stat cache. Use clearstatcache() to clean that cache.

posted date: 2009-04-13 23:47:00


Re: Check whether a Directory Exists in PHP#4
You could try this:if(is_dir($dir) && is_writeable($dir)){ // ...}

posted date: 2009-04-13 23:50:00


Re: Check whether a Directory Exists in PHP#5
not a solution to the problem, because non-writeable directories are directories too.

posted date: 2009-04-13 23:53:00


Re: Check whether a Directory Exists in PHP#6
This was a reported bug in php 5.2, though I can no longer find the link to the bug report.

posted date: 2009-04-13 23:55:00


Re: Check whether a Directory Exists in PHP#7
bool file_exists ( string $filename )Checks whether a file or directory exists. http://php.net/manual/en/function.file-exists.php

posted date: 2012-03-22 07:00:00


Re: Check whether a Directory Exists in PHP#8
+1 for the clearstatcache info, always useful to know

posted date: 2012-08-09 00:04:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.