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
+8.5k Golang : Accept any number of function arguments with three dots(...)
+14.4k Golang : Normalize unicode strings for comparison purpose
+10.6k Golang : How to transmit update file to client by HTTP request example
+8.1k Golang : Implementing class(object-oriented programming style)
+12.3k Golang : Sort and reverse sort a slice of bytes
+6.9k Golang : Gorrila mux.Vars() function example
+6.6k Golang : How to setup a disk space used monitoring service with Telegram bot
+14.9k Golang : How to get Unix file descriptor for console and file
+11.8k Golang : Pagination with go-paginator configuration example
+21.7k Golang : Convert seconds to minutes and remainder seconds
+9.7k CodeIgniter : Load different view for mobile devices
+18.5k Golang : Delete duplicate items from a slice/array