mkdir() 不工作
我的代码
mkdir("/some/absolute/path",0777);
无法
mkdir("relative/path", 0777);
正常工作,安全模式已关闭,我什至尝试将所有父文件夹设置为 777。
有什么想法吗?
编辑:我确实打开了错误报告,沮丧的是我已经 777 了整个路径只是为了确保这不是问题。这一定是一件极其简单的事情。
编辑编辑:为所有提出建议的人投票……但我不会选择答案,因为这仍然没有解决,但我再次认为这将是永远悬而未决的问题之一。
编辑x 3:所以我对这个问题有最不满意的解决方案......我从一个干净的虚拟机映像开始,重试它,现在它可以工作了。不是开玩笑。
My code
mkdir("/some/absolute/path",0777);
and
mkdir("relative/path", 0777);
is not working, safe mode is turned off, and I've even tried setting all of the parent folders to 777.
Any ideas?
EDIT: I do have error reporting turned on, in my frustration I've 777'd the whole path just to make sure that, that isn't the issue. It's gotta be something stupidly simple going on.
EDIT EDIT: Upvotes for everyone who responded with suggestions... But I'm not going to select an answer since this still isn't resolved, but then again I think this is going to be one of those ones left open forever.
EDIT x 3: So I have the most unsatisfactory resolution to this question ever... I started with a clean VM image, retried it and it works now. No joke.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
所有父目录都存在吗?
如果没有,您需要启用递归(假设这里是 PHP5):
编辑:没有看到隐藏的注释说从
var
向下的每个目录都设置为全局可写,所以我打赌目录路径存在,上面的内容不会有帮助。对不起!Do all of the parent directories exist?
If not, you'll need to enable recursion (assuming PHP5 here):
EDIT: Didn't see the hidden comment saying that every directory from
var
downward was set to world-writable, so I'm betting the directory path exists and the above won't be helpful. Sorry!您是否尝试递归地创建这些目录,就像在命令行上使用
mkdir -p
所做的那样?如果是这样,请将true
指定为mkdir
。为了呼应之前的建议,请指定您收到的错误消息。如果您没有收到任何消息,请在调用之前使用:
error_reporting(-1); // 所有消息
和ini_set('display_errors', 'On');
。Are you trying to create those directories recursively, like you would do with
mkdir -p
on the command line? If so, specifytrue
as the third parameter tomkdir
.And just to echo the previous suggestions, PLEASE specify the error messages you are getting. If you are not getting any, use this before your call:
error_reporting(-1); // ALL messages
andini_set('display_errors', 'On');
.如果有人遇到这个问题.. 我可以给你一个答案,我花了 2 个小时来找到.. 我尝试使用完整路径和“../mydirectoryname”。
尝试使用:
而不是..
If anyone gets stuck with this problem.. there's one answer I can give you that I spend 2 hours on finding.. I tried with using a full path, and "../mydirectoryname".
Try using:
Instead of..
您是否尝试过尽可能短的测试?
mkdir('目录',0777);
如果这不起作用,我会尝试使用像 0755 这样的标准 CHMOD 创建(这是完全随机的猜测,也许服务器不允许通过 PHP 创建 0777)
如果这不起作用,我会说服务器可能需要不同的设置/php 文件夹上没有写权,也许你可以询问你的主机提供商?
Have you tried with the shortest test possible?
mkdir('directory',0777);
If this does not work I would try creating with a standard CHMOD like 0755 (this is a totally random guess, maybe the server won't allow creating 0777 via PHP)
if this don't work I would say the server probably need different setup / php doesn' thave the writting right on folder, maybe you could ask your host provider?
我有类似的问题,我发现我的驱动器上没有剩余的可用空间。使用命令
df
(在 Linux 上)检查您的驱动器有多满。在这种情况下,root 可能被允许创建文件和文件夹,因为他有预先预留的空间。如果您以root
用户身份从命令行运行脚本 - 不会出现错误,但如果您的脚本由apache
运行,则会发生错误。I have similar problem and I found out, that I have no free space left on my drive. Check with command
df
(on linux) how full is your drive. It is possible that root is allowed to create files and folders in this situation, because he has pre-reserved space. If you run you script from command-line asroot
user - there is no error, but if your script is run byapache
, then error occure.为了将来的参考,问题可能来自于您尝试创建新目录的目录没有足够的权限。
例如,您的索引目录可能如下所示:
index.php new_dirs_here
如果
new_dirs_here
没有足够的权限,那么您无法在其中创建目录。为了解决这个问题,我会使用以下命令:
chmod 777 new_dirs_here
我现在不担心安全问题,只是想解决眼前的问题。您当然可以查找更好的权限设置,但我们的想法是您的
new_dirs_here
应该具有足够的权限。然后,您的 mkdir() 函数应该可以正常工作。
祝你好运
For future references, the problem might come from the possibility that the directory where you're trying to create your new directory doesn't have enough permission.
For instance, your index directory might look like this:
index.php new_dirs_here
if
new_dirs_here
doesn't have enough permission then you can't create direcories inside.To solve this, I'd use the command:
chmod 777 new_dirs_here
I'm not worrying about security now, Just trying to solve the immediate problem. You could of course look up a better permission settings, but the idea is that your
new_dirs_here
should have enough permissions.Then, your
mkdir()
dunction should work just fine.Good luck
确保父目录具有正确的写入权限,这是我的问题
Make sure the parent directories have correct write permissions, that was my problem
mkdir
在不带-p
调用时仅创建一个目录。路径
/usr/local/myfolder/
中的目录丢失,这就是您收到错误的原因。如果您调用 mkdir -p,也会创建丢失的路径。使用 -p 选项的另一个效果是,当目录已存在时,
mkdir
-p 不会抱怨。这就是为什么这个变体在脚本中经常使用的原因。mkdir
only creates one single directory when called without-p
.A directory in the path
/usr/local/myfolder/
is missing, this is why you get the error. If you callmkdir
-p, the missing path is created as well.Another effect of using the -p option is that
mkdir
-p does not complain when the directory already exists. This is why this variant is frequently used in scripts.chown www-data:www-data(地址目录)
chown www-data:www-data (address directory)
您缺少路径名参数周围的引号。
You're missing quotes around the path name parameter.
您必须将属性放在引号中:
You must take the attribute in quotes: