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
+35k Golang : Strip slashes from string example
+6.7k Golang : Pat multiplexer routing example
+10.3k Golang : Select region of interest with mouse click and crop from image
+21.2k Golang : Encrypt and decrypt data with TripleDES
+12k Golang : flag provided but not defined error
+5.6k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+14.5k Golang : Find commonalities in two slices or arrays example
+10.7k Golang : How to transmit update file to client by HTTP request example
+24.9k Golang : Storing cookies in http.CookieJar example
+36.1k Golang : Validate IP address
+6.6k Swift : substringWithRange() function example
+7.6k Golang : Generate human readable password