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
+29.5k Golang : Validate IP address
+8k Golang : Delay or limit HTTP requests example
+5.3k Golang : Process json data with Jason package
+9.3k Golang : Gorilla web tool kit secure cookie example
+8.9k Golang : Byte format example
+4.7k Golang : Calculate pivot points for a cross
+3.2k Golang : Get FX sentiment from website example
+7.9k Golang : Get login name from environment and prompt for password
+12.4k Golang : Loop each day of the current month example
+6.3k Golang : Sort lines of text example
+7.5k Golang : Resumable upload to Google Drive(RESTful) example
+10.7k Golang : convert rune to unicode hexadecimal value and back to rune character