Create directory with current year and month name - php :
Here i will explain about how to create folder / directory with the current year and month name. It is very usefull to seperate the uploaded image or file with the particular year and month name.
Here we will use the simple concept to create this. here date() function is used to get current year and month details.
For Example :
if (!file_exists("techniq/".date('Y').'/'.date('m'))) {
mkdir("techniq/".date('Y').'/'.date('m'), 0777, true);
}
In the above example three php pre defined function are used. that is file_exists() , date() , mkdir().
1. file_exists() :- This function is used to check the given path for directory is available or not. It will return bool value. If the file exists then it will return TRUE otherwise FALSE.
2. date() :- This function is used to get current timestamp. here i used date('Y'), it will return current year in numeric i.e., 2013. and date('m') return current month in the format of 08.
Note : Read more about date() : http://techniqzone.blogspot.in/2013/07/php-to-get-yesterdayprevious-date.html
3. mkdir() :- This function is used to create a directory with the give filename or path. here i used 0777 argument for set folder permission for the created directory.
This method is easy to create Folder(directory) with current Year and Month name in php.
Here we will use the simple concept to create this. here date() function is used to get current year and month details.
For Example :
if (!file_exists("techniq/".date('Y').'/'.date('m'))) {
mkdir("techniq/".date('Y').'/'.date('m'), 0777, true);
}
In the above example three php pre defined function are used. that is file_exists() , date() , mkdir().
1. file_exists() :- This function is used to check the given path for directory is available or not. It will return bool value. If the file exists then it will return TRUE otherwise FALSE.
2. date() :- This function is used to get current timestamp. here i used date('Y'), it will return current year in numeric i.e., 2013. and date('m') return current month in the format of 08.
Note : Read more about date() : http://techniqzone.blogspot.in/2013/07/php-to-get-yesterdayprevious-date.html
3. mkdir() :- This function is used to create a directory with the give filename or path. here i used 0777 argument for set folder permission for the created directory.
This method is easy to create Folder(directory) with current Year and Month name in php.
0 comments:
Post a Comment