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.2k Golang : How to determine a prime number?
+10k Golang : Check if user agent is a robot or crawler example
+20.8k Golang : Saving private and public key to files
+11k Golang : Get UDP client IP address and differentiate clients by port number
+7.9k Golang : Lock executable to a specific machine with unique hash of the machine
+7.4k Golang : Fixing Gorilla mux http.FileServer() 404 problem
+14.5k Golang : Parsing or breaking down URL
+9.2k Golang : Gonum standard normal random numbers example
+5.8k Unix/Linux/MacOSx : Get local IP address
+6.4k PHP : Proper way to get UTF-8 character or string length
+11.2k Golang : Simple image viewer with Go-GTK
+26.2k Golang : Convert IP address string to long ( unsigned 32-bit integer )