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
+11.5k Golang : Calculations using complex numbers example
+21.4k Golang : Encrypt and decrypt data with TripleDES
+17.4k Golang : Clone with pointer and modify value
+5.9k Javascript : Get operating system and browser information
+28k Golang : Connect to database (MySQL/MariaDB) server
+5.7k Unix/Linux : How to test user agents blocked successfully ?
+11.6k Golang : Secure file deletion with wipe example
+15.3k Golang : ROT47 (Caesar cipher by 47 characters) example
+16.7k Golang : Set up source IP address before making HTTP request
+15k JavaScript/JQuery : Detect or intercept enter key pressed example
+6.8k Golang : constant 20013 overflows byte error message
+13.8k Golang : convert rune to unicode hexadecimal value and back to rune character