-1

I am using XMPP server in windows 7 for executing PHP script. I have project folder in htdocs which contain my projects PHP script with required bootstrap, CSS and jquery files. I have three subfolders in the project folder as student, teacher, and admin. I have one folder as the report in admin. I am working in student folder, How to create report directory in admin folder if report folder does not exist?

I want to create folder or Director in parent folder's not in the same folder.

Fabio
  • 23,183
  • 12
  • 55
  • 64
  • Possible duplicate of [Create a folder if it doesn't already exist](http://stackoverflow.com/questions/2303372/create-a-folder-if-it-doesnt-already-exist) – KhorneHoly Dec 23 '16 at 14:46
  • 1
    what did you try so far? Do you have any code to show us? Did it work? Did it throw any error? – Dragos Dec 23 '16 at 14:46
  • @Dragos :- Here is my code. –  Dec 23 '16 at 14:50
  • @Dragos :- Here is my code.`$rebuilt_dir = "../admin/report"; if(!is_dir($rebuilt_dir)){ mkdir($rebuilt_dir) }` –  Dec 23 '16 at 14:52
  • @Dragos :- this is part of index.php which is written in student folder. –  Dec 23 '16 at 14:55
  • @varlogtim :- how we could up to that folder? Do you suggest me? –  Dec 23 '16 at 14:56
  • I would add: `if(!is_dir($rebuilt_dir) { if(!mkdir($rebuilt_dir)) { echo "Error: ".$!; } }` - This should print the error if you are getting one. – Tim Dec 23 '16 at 14:59
  • @varlogtim :- I want to check it in previous/parent folder, not in the same folder. so how could I specify path their? –  Dec 23 '16 at 15:01

1 Answers1

0

If you want to get the parent directory you can use the function dirname. In your example it would look as follows:

$rebuilt_dir = "../admin/report";
$parent_dir = dirname($rebuilt_dir);

if(!is_dir($parent_dir)) { 

    if(!mkdir($parent_dir))
        echo "Error creating dir: ".$!;

    if(!is_dir($rebuilt_dir)) { 
        if(!mkdir($rebuilt_dir))
            echo "Error creating dir: ".$!;

}
Tim
  • 2,139
  • 13
  • 18