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
+13.9k Golang : Qt progress dialog example
+10k Golang : Function wrapper that takes arguments and return result example
+8.3k Golang : Tell color name with OpenCV example
+30.5k Golang : How to redirect to new page with net/http?
+28.3k Golang : Connect to database (MySQL/MariaDB) server
+8.6k Golang : How to check if input string is a word?
+24.2k Golang : Upload to S3 with official aws-sdk-go package
+23.3k Golang : Print out struct values in string format
+19.4k Golang : Check whether a network interface is up on your machine
+6.2k PageSpeed : Clear or flush cache on web server
+11.3k Golang : Calculate Relative Strength Index(RSI) example
+7.8k Golang : How to execute code at certain day, hour and minute?