CodeIgniter/PHP : Create directory if does not exist example
Problem :
How to check if a directory exist or not? If not, how to create a directory?
NOTE :
This solution should be applicable for all PHP based frameworks.
Solution :
Use the is_dir()
function to test if a directory exist or not. If not, then proceed to mkdir(). For example :
$directoryname = "dirname";
if (!is_dir('uploads/'.$directory_name)) {
mkdir('./uploads/' . $date, 0777, TRUE);
}
The permission setting 0777
is just an example, you can choose to have different setting.
References :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.8k Golang : On lambda, anonymous, inline functions and function literals
+4.5k AWS S3 : Prevent Hotlinking policy
+14.6k Golang : Check if IP address is version 4 or 6
+8.8k Golang : Command line file upload program to server example
+5.1k Golang : Muxing with Martini example
+3k Java : Generate multiplication table example
+11.7k Golang : How to get URL port?
+4.5k Golang : Shuffle array of list
+4.5k Golang : Detect face in uploaded photo like GPlus
+6.7k Golang : Implementing class(object-oriented programming style)