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
+12.8k Swift : Convert (cast) Int to String ?
+10.3k Golang : Select region of interest with mouse click and crop from image
+14k Golang : syscall.Socket example
+21.5k Golang : Convert string slice to struct and access with reflect example
+6.1k Unix/Linux : Use netstat to find out IP addresses served by your website server
+19.9k Golang : How to get struct tag and use field name to retrieve data?
+22.7k Golang : Test file read write permission example
+5.8k PHP : How to check if an array is empty ?
+13.1k Golang : Verify token from Google Authenticator App
+5.8k nginx : force all pages to be SSL
+14.3k Golang : Find network of an IP address
+8.8k Golang : automatically figure out array length(size) with three dots