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.2k Golang : Create new color from command line parameters
+14.2k Golang : Reverse IP address for reverse DNS lookup example
+9.5k Golang : Timeout example
+13.5k Golang : error parsing regexp: invalid or unsupported Perl syntax
+11.8k Golang : Concurrency and goroutine example
+14.8k Golang : GUI with Qt and OpenCV to capture image from camera
+31.3k Golang : Calculate percentage change of two values
+7.2k Golang : Transform lisp or spinal case to Pascal case example
+16.2k Golang : How to reverse elements order in map ?
+6.4k Javascript : Generate random key with specific length
+5.3k Golang : Customize scanner.Scanner to treat dash as part of identifier
+5.6k PHP : Fix Call to undefined function curl_init() error