I am getting this error when trying to use mkdir()
function in PHP.
basically I am creating a sundomain on my server based on an input field
in the HTML form named (inPut
).
now I am trying to create a directory in that subdomain after it has been created.
so I use the following code :
$subDomain= $_POST['inPut'];
mkdir("$subDomain.mydoamin.com/newDirectory", 0755);
but I get the following error:
Warning: mkdir() [function.mkdir]: No such file or directory in line 99.
and on line 99 is this:
mkdir("$subDomain.mydoamin.com/newDirectory", 0755);
as a note: the subdomain gets created successfully. so I know the subdomain 100% does exist on my server. I just don't know why I get that error!
could someone please advise on this issue?
Thanks in advance.
Try to put third parameter. The method signature is:
bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
So your code would be:
mkdir(__DIR__ . "/$subDomain.mydoamin.com/newDirectory", 0755, true);
Try this, [EDITED]
mkdir($_SERVER['DOCUMENT_ROOT'] . $subDomain . '/newDirectory', 0755);
mkdir
is only working with the directory path, not the URL or domain.
mkdir('sub.domain.com/newdir'); // return false
mkdir('/public_html/subdomain/newdir'); //return true if /public_html/subdomain is exist
You should have to point to your subdomain's absolute path, not the URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With