MkDir无法创建目录PHP [英] MkDir Failed creating directory PHP
问题描述
我正在尝试使用PHP创建目录,这可行:
I am trying to create a directory using PHP this works:
<?php
$uid = "user_615";
$thisdir = getcwd();
if(mkdir($thisdir ."/userpics/" . $uid , 0777))
{
echo "Directory has been created successfully...";
}
else
{
echo "Failed to create directory...";
}
?>
但这不起作用
<?php
session_start();
$uid = $_SESSION['username'];
$thisdir = getcwd();
if(mkdir($thisdir ."/userpics/" . $uid , 0777))
{
echo "Directory has been created successfully...";
}
else
{
echo "Failed to create directory...";
}
?>
是的,会话变量中填充的内容与"user_615"上面的内容完全相同,那么为什么第二个变量会失败?
Yes the session variable is populated with the exact same thing as above 'user_615' so why would the second one be failing?
所以我采纳了@stefgosselin的建议,并重新设计了代码
So I took the suggestion of @stefgosselin and re-designed the code to be
<?php
session_start();
$uid = $_SESSION['username'];
$thisdir = getcwd() . "/userpics" . $uid;
if(mkdir($thisdir , 0777))
{
echo "Directory has been created successfully...";
}
else
{
echo "Failed to create directory...";
echo "Your thisdir Variable is:'" . $thisdir . "'" ;
}
?>
输出为
无法创建目录...您的此目录变量为:'/unified/b/bis/www.mysite.com/jou/userpics/user_615
Failed to create directory...Your thisdir Variable is:'/unified/b/bis/www.mysite.com/jou/userpics/user_615
还有什么其他想法会导致Session变量无法在创建目录中使用?
Any other ideas on what would cause the a Session variable not to be able to used in creating a directory?
推荐答案
作为一个小技巧,我只是将所有$thisdir
放入变量中,然后检查其输出是否合计您期望的结果.
As a small tip, I would simply put all of $thisdir
in a variable and check if the output of that adds up to the result you are expecting.
IE:在变量中定义$thisdir ."/userpics/" . $uid
将使您能够轻松输出并验证传递给mkdir
的参数值.
IE: Having $thisdir ."/userpics/" . $uid
defined in a variable would give you the possibility to easily output and validate the argument value you are passing to mkdir
.
调整了较小的措词,以获得更好的英语翻译.抱歉,以上还不清楚,Wesley明白了我笨拙地试图提出的简单观点.
Adjusted minor phrasing for better english translation. Sorry above wasn't clear, Wesley understood the simple point I was clumsily trying to make.
这篇关于MkDir无法创建目录PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!