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.

  1. function createNewDirectory()
  2. {
  3. $sCurrDate = date("Y-m-d"); //Current Date
  4. $sDirPath = 'http://example.com/files/'.$sCurrDate.'/'; //Specified Pathname
  5. if (!file_exists ($sDirPath))
  6. {
  7. mkdir($sDirPath,0777,true);
  8. }
  9. }
The above function will create a dynamic directory on the server. The path of the created directory will be: https://example.com/files/2015-10-12 provided the current date is Oct 12, 2015.