I have to create a root folder that uses the $username
variable (coming from a previous section of the script), and then, inside this root folder, I need to create the /JS
, /PHP
and the /CSS
subfolders.
I have tried the following (just for the JS subfolder) but it does not work. I receive no error but the JS subfolder is not created (the root folder is created):
$rootpath = $username. '/';
$jspath = $rootpath. '/js/';
return is_dir($rootpath) || mkdir($rootpath, 0777, true);
return is_dir($jspath) || mkdir($jspath);
What am i doing wrong?
Thank you in advance.
Kindest regards,
3
Answers
I will advise you to use a function
I try to explain your code:
is_dir($rootpath) return true if the $rootpath exist, then mkdir($rootpath, 0777, true); do not get executed.
If $rootpath does not exist, then mkdir($rootpath, 0777, true); is executed
So at this point you have $rootpath folder and the code exit (or better return) due to the return in front of the commands
Your code should be as follow:
@roberto-braga has explained your code very well. There is another solution i like to give you. If you sure that certain directories is not exist and directly you want to create. You can use this piece of code.
I like to give you another suggestion that before try the code make sure you have proper permission to create , edit and delete folder.