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
+9k Android Studio : Simple input textbox and intercept key example
+3.9k Golang : A program that contain another program and executes it during run-time
+22.2k Golang : Print out struct values in string format
+5.5k Golang : Embedded or data bundling example
+20.7k Golang : How to run Golang application such as web server in the background or as daemon?
+11.3k Golang : Sort and reverse sort a slice of bytes
+5.5k Unix/Linux : Use netstat to find out IP addresses served by your website server
+17.8k Golang : How to make function callback or pass value from function as parameter?
+6.3k Golang : Scanf function weird error in Windows
+18.3k Golang : Archive directory with tar and gzip
+8k Golang : Inject/embed Javascript before sending out to browser example
+21.6k Golang : Strings to lowercase and uppercase example