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.6k Golang : Reverse by word
+7k Golang : Takes a plural word and makes it singular
+6.8k Swift : substringWithRange() function example
+39.5k Golang : Remove dashes(or any character) from string
+26.6k Golang : How to check if a connection to database is still alive ?
+15.6k Golang : Get checkbox or extract multipart form data value example
+3.7k Golang : Switch Redis database redis.NewClient
+38k Golang : Read a text file and replace certain words
+19.5k Golang : Example for DSA(Digital Signature Algorithm) package functions
+32.9k Golang : How to check if a date is within certain range?
+9k Golang : How to use Gorilla webtoolkit context package properly