php - Setting up a log directory -
i want create new folder if there isn't 1 created. in order wrote:
//set log directory if(is_dir(dirname(log_path))) { } else { mkdir(log_path, 0777, true); echo "directory created. ". log_path ."<br />"; }
log_path = e:\xampp\htdocs\photo\logs\
there photo folder, there no logs folder (i want create folder).
am missing something, because if statement here true. shouldn't be.
dirname(log_path)
returns parent of log_path
(e:\xampp\htdocs\photo
), if
statement true when photo
folder exists, not when logs
folder exists.
you should modify condition be:
if (is_dir(log_path)) { } else { mkdir(log_path, 0777, true); echo "directory created. ". log_path ."<br />"; }
and, if leaving first branch empty, negate condition:
if (!is_dir(log_path)) { mkdir(log_path, 0777, true); echo "directory created. ". log_path ."<br />"; }
and way, mkdir
call may fail if don't have permissions create new folder there, should check if fails or not:
if (!is_dir(log_path)) { if (mkdir(log_path, 0777, true)) { echo "directory created. ". log_path ."<br />"; } else { throw new exception("can't create folder " . log_path); } }
Comments
Post a Comment