Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: mkdir() [function.mkdir]: No such file or directory PHP?

Tags:

php

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.

like image 901
user3454730 Avatar asked Apr 06 '14 16:04

user3454730


3 Answers

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);
like image 79
Andy Librian Avatar answered Nov 15 '22 01:11

Andy Librian


Try this, [EDITED]

 mkdir($_SERVER['DOCUMENT_ROOT'] . $subDomain . '/newDirectory', 0755);
like image 30
Ethan Webster Avatar answered Nov 15 '22 00:11

Ethan Webster


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.

like image 23
bprayudha Avatar answered Nov 15 '22 00:11

bprayudha