Create a php folder in a specific repository

Asked

Viewed 31 times

-1

I create a folder for each user, but this creating where this my php file, I want to create in a folder inside this repository where the file, but it is not going, it is simple but I am new.

$parts = explode('/', $dir);
        $file = 'dados.json';
        $dir = $data;
        foreach($parts as $part)
            if(!is_dir($dir .= "/$part")) mkdir($dir);
        file_put_contents("$dir/$file", $json);

I tried that:

$parts = explode('/', $dir);
        $file = 'dados.json';
        $dir = $data;
        $past = 'Users'
        foreach($parts as $part)
            if(!is_dir($dir .= "/$part")) mkdir($dir);
        file_put_contents("$past/$dir/$file", $json);

2 answers

-1

if the code is working and just creating the folder in the wrong place, try this:

               $parts = explode('Users/', $dir);
                $file = 'dados.json';
                $dir = $data;
                foreach($parts as $part)
                if(!is_dir($dir .= "/$part")) mkdir("C:\Users\$dir");
                    file_put_contents("C:\Users\$dir\$file", $json);

where "C: Users " would be the complete path from where you want to create the folder

-3


Answer:

                   $parts = explode('Users/', $dir);
                    $file = 'dados.json';
                    $dir = $data;
                    foreach($parts as $part)
                    if(!is_dir($dir .= "/$part")) mkdir("Users/$dir");
                        file_put_contents("Users/$dir/$file", $json);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.