tags:

views:

36

answers:

6

hi

i want know find the directory is already there or not...

if not i would like to create the directory...

my coding is below...

    $da = getdate();

 $dat = $da["year"]."-".$da["mon"]."-".$da["mday"];

 $m = md5($url)."xml";

 if(is_dir($dat))
 {
  chdir($dat);

  $fh = fopen($m, 'w');

  fwrite($fh, $xml); 

  fclose($fh);

  echo "yes";
 }
 else
 {
   mkdir($dat,0777,true); 

  chdir($dat); 

  $fh = fopen($m, 'w');

  fwrite($fh, $xml); 

  fclose($fh); 

  echo "not";
 } 

thanks and advance

A: 

http://php.net/manual/en/function.file-exists.php

Checks whether a file or directory exists.

The MYYN
A: 

file_exists()

Mark Baker
File exists will also test for regular files, though.
Joseph Mastey
A: 

take a look at file_exists() - it also works for directories.

oezi
+7  A: 

Use is_dir, which checks whether the path exists and is a directory then mkdir.

function mkdir_if_not_there($path) {
  if (!is_dir($path)) {
    // Watch out for potential race conditions here
    mkdir($path);
  }
}
Dominic Rodger
i want to check the folder s exist or not...please see my coding...i will just update...
zahir hussain
Err... what? That's what my function does!
Dominic Rodger
A: 

I would start with the PHP docs.

Inkspeak
A: 

Use is_dir:

$pathname = "/path/to/dir";
if(is_dir($pathname)) {
   // do something
}
Joseph Mastey