Create a directory in php

The mkdir() php function can be used to create a directory provided that the necessary file permissions exist.

Example on mkdir():

<?php 
if (file_exists("/temp/test")) {
  print("Test Directory already exists.\n");
} else {
  mkdir("/temp/test");
  print("Test Directory created.\n");
}
?>

Output – first execution

Test Directory created.

If you run this script again, it will print:

Test Directory already exists.

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

Filed Under: PHP File Handling

Tags:

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.