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
+21.8k Golang : How to run Golang application such as web server in the background or as daemon?
+9.8k Golang : Test a slice of integers for odd and even numbers
+4.2k Linux/MacOSX : Search and delete files by extension
+16.1k Golang : Send email and SMTP configuration example
+7.3k Javascript : Push notifications to browser with Push.js
+12.6k Golang : Get terminal width and height example
+15.3k Golang : How to convert(cast) IP address to string?
+6k Golang : Extract sub-strings
+7.9k Golang : Tell color name with OpenCV example
+15.1k Golang : ROT47 (Caesar cipher by 47 characters) example
+7.1k Golang : Word limiter example
+15.3k Golang : Get checkbox or extract multipart form data value example