PHP - why is_dir returns TRUE when the directory does not exist?

My current directory structure is as follows:

C:\xampp\htdocs\PHP_Upload_Image_MKDIR

In other words, the following directories do NOT exist at all.

C:\xampp\htdocs\PHP_Upload_Image_MKDIR\uploaded
C:\xampp\htdocs\PHP_Upload_Image_MKDIR\uploaded\s002

The problem is that when I run the following script, the is_dir function always returns TRUE.

Based on the manual http://us2.php.net/manual/en/function.is-dir.php is_dir: Returns TRUE if the file name exists and is a directory, FALSE otherwise.

Did I miss something?

thank

$userID = 's002';
$uploadFolder = '/PHP_Upload_Image_MKDIR/uploaded/';
$userDir = $uploadFolder . $userID;
echo '<br/>$userDir: ' . $userDir . '<br/>';

if ( is_dir ($userDir))
{
  echo "dir exists"; // always hit here!!!
}
else 
{
  echo "dir doesn't exist";
}

mkdir($userDir, 0700);
C:\xampp\htdocs\PHP_Upload_Image_MKDIR>dir /ah
 Volume in drive C is System
 Volume Serial Number is 30B8-2BB2

 Directory of C:\xampp\htdocs\PHP_Upload_Image_MKDIR

File Not Found

C:\xampp\htdocs\PHP_Upload_Image_MKDIR>


//////////////////////////////////////////////////////////

Based on the comments of Artefacto:

Here is the output of C:\PHP_Upload_Image_MKDIR\uploaded\s005
 echo '<br/>' . realpath($userDir) . '<br/>';

Thank you for your decision.

Regards

+3
source share
3 answers

, , PHP_Uploaded_Image_MKDIR/uploaded/s002, , .

C:\xampp\htdocs\ , . , , .

+1

script , is_dir($userDir) true - () script:

mkdir($userDir, 0700);

rmdir() - .

is_dir(), , / . - false, , , is_dir() :

if ( is_dir ("/PHP_Upload_Image_MKDIR/uploaded/lkjlkjlkjkl"))
+1

Source: https://habr.com/ru/post/1762066/


All Articles