Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

MkDir PHP problem

Guest
Sep 25, 2009 Sep 25, 2009

I have a simple mkdir script, that creates a directory that contains 3 sub-fodlers, on my server.

The script works fine on my Apache server, however if the directory already exists, an error message should be displayed, but I don't think the script gets that far on my IIS:

// URL
$url = "//Server/Folder1/Folder2/";

// Create It
$create = mkdir("$url");
mkdir("$url/Sub1");
mkdir("$url/Sub2");
mkdir("$url/Sub3");

if ($create) {
  $mess = $ref = $_SERVER['HTTP_REFERER']; header( 'refresh: 0; url='.$ref);;
  $query = sprintf("UPDATE tbl_freelancer SET freedir='y' WHERE freeid=%s", GetSQLValueString($colname_rsFreelance_Dir, "int"));
  $result = mysql_query($query, $conndb2) or die(mysql_error());
}
else {
  $mess = "<p>Directory could not be created.</p>";
}

The error (on my IIS server):

PHP Warning: mkdir() [function.mkdir]: File exists  in C:\Web\QT\admin\script.php on line 85

Is there a way of getting this to work?

TOPICS
Server side applications
602
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 25, 2009 Sep 25, 2009

Before attempting to create a new directory, you should first check to see whether it already exists.

if (!is_dir($url)) {

  mkdir($url);

} else {

  $error = "$url already exists";

}

Translate
LEGEND ,
Sep 25, 2009 Sep 25, 2009
LATEST

Before attempting to create a new directory, you should first check to see whether it already exists.

if (!is_dir($url)) {

  mkdir($url);

} else {

  $error = "$url already exists";

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines