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
+17.4k Golang : Check whether a network interface is up on your machine
+26.5k Get file path of temporary file in Go
+3.9k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+10.4k Golang : Surveillance with web camera and OpenCV
+4.5k Golang : Shortening import identifier
+13.3k Golang : Convert(cast) int to float example
+7.9k Golang : How to get username from email address
+5.8k Golang : How to fix html/template : "somefile" is undefined error?
+12.5k Golang : Activate web camera and broadcast out base64 encoded images
+5.2k Golang : Experimental emojis or emoticons icons programming language
+16.8k Golang : Display list of time zones with GMT
+4.5k Clean up Visual Studio For Mac installation failed disk full problem