警告:mkdir() [function.mkdir]:没有这样的文件或目录 PHP?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22896920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: mkdir() [function.mkdir]: No such file or directory PHP?
提问by user3454730
I am getting this error when trying to use mkdir()
function in PHP.
尝试mkdir()
在 PHP 中使用函数时出现此错误。
basically I am creating a sundomain on my server based on an input field
in the HTML form named (inPut
).
基本上,我正在我的服务器上基于input field
名为 ( inPut
)的 HTML 表单创建一个 sundomain 。
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:
第 99 行是这样的:
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!
请注意:子域已成功创建。所以我知道我的服务器上确实存在 100% 的子域。我只是不知道为什么我会收到那个错误!
could someone please advise on this issue?
有人可以就这个问题提出建议吗?
Thanks in advance.
提前致谢。
回答by Andy Librian
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);
回答by Ethan Webster
Try this, [EDITED]
试试这个,[编辑]
mkdir($_SERVER['DOCUMENT_ROOT'] . $subDomain . '/newDirectory', 0755);
回答by bprayudha
mkdir
is only working with the directory path, not the URL or domain.
mkdir
仅使用目录路径,而不是 URL 或域。
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.
您应该指向子域的绝对路径,而不是 URL。