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.9k Golang : Display list of countries and ISO codes
+30.6k Golang : bufio.NewReader.ReadLine to read file line by line
+13.1k Golang : Image to ASCII art example
+5.6k Golang : Generate multiplication table from an integer example
+8.9k Golang : How to control fmt or log print format?
+6.2k PHP : Shuffle to display different content or advertisement
+17.1k Golang : [json: cannot unmarshal object into Go value of type]
+15.3k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+10.5k Golang : How to transmit update file to client by HTTP request example
+10.5k Golang : Sieve of Eratosthenes algorithm
+8.7k Golang : Capture text return from exec function example
+5.6k PHP : Get client IP address