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.8k Golang : Find the longest line of text example
+20.7k Android Studio : AlertDialog and EditText to get user string input example
+17.7k Convert JSON to CSV in Golang
+14.9k Golang : Submit web forms without browser by http.PostForm example
+16k Golang : Read large file with bufio.Scanner cause token too long error
+6.9k Golang : Muxing with Martini example
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+48.6k Golang : Upload file from web browser to server
+21.8k Golang : How to reverse slice or array elements order
+11.7k Golang : Concurrency and goroutine example
+27.9k Golang : Decode/unmarshal unknown JSON data type with map[string]interface
+14.8k Golang : Get URI segments by number and assign as variable example