Home » Support » Help Articles » Creating a Dynamic Directory Folder with PHP

Creating a Dynamic Directory Folder with PHP

Back to Help Articles Home

If you have a site with large number of users where they upload pictures or documents or videos, then you should create directories during run-time.

The function 'mkdir' creates a directory in the specified path. The following are the parameters of creating a directory:

  1. pathname: Specified path of the directory
  2. mode: The default mode is 0777.

Example: Let us create a dynamic directory based on the current date.

function createNewDirectory()
$sCurrDate = date("Y-m-d"); //Current Date
$sDirPath = 'http://example.com/files/'.$sCurrDate.'/'; //Specified Pathname
if (!file_exists ($sDirPath))

The above function will create a dynamic directory on the server. The path of the created directory will be: 'http://example.com/files/2015-10-12/' provided the current date is Oct 12, 2015.

You are done with.

Updated on Nov 11, 2015

The techReview is an online magazine by Batoi and publishes articles on current trends in technologies across different industry verticals and areas of research. The objective of the online magazine to provide an insight into cutting-edge technologies in their evolution from labs to market.

Visit techReview

English - IN (USD)
New Users? Signup.     Existing Users? Login.