Creating a Dynamic Directory Folder with PHP

Learn how-to create a dynamic directory folder with PHP.

Batoi Corporate Nov 11, 2015 Facebook Twitter LinkedIn Pinterest

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 = ''.$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: provided the current date is Oct 12, 2015.

Need our assistance? We are available.

Learn More About Our Platform?
Schedule a Demo
An Existing Customer?
Get Support
Want Managed Service?
Request for a Quote
Report an Error