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
+19k Golang : Fix cannot download, $GOPATH not set error
+9.3k Golang : Copy map(hash table) example
+4.3k Mac OSX : Get disk partitions' size, type and name
+8.9k Golang : How to control fmt or log print format?
+19.7k Swift : Convert (cast) Int to int32 or Uint32
+7.2k Golang : Handling Yes No Quit query input
+5.8k Golang : Get missing location after unmarshal binary and gob decode time.
+9.6k Golang : Check if user agent is a robot or crawler example
+11.9k Golang : How to display image file or expose CSS, JS files from localhost?
+15.9k Golang : How to extract links from web page ?
+7.5k Setting $GOPATH environment variable for Unix/Linux and Windows