PHP mkdir();不工作 [英] PHP mkdir(); not working

查看:140
本文介绍了PHP mkdir();不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试Mkdir函数,该函数在我正在研究的项目中将非常有用.我尝试了最简单的代码,但无法创建所需的文件夹.

I've been trying the function Mkdir that will be usefull in the project i'm working on. I've tried the simplest code possible but I can't get it to create the folder I want.

我尝试更改文件夹权限,但是没有更改(Nor 755或777),并且代码不断返回失败.

I've tried to changes my folder permissions, but that doesn't change (Nor 755 or 777) and the code keeps returning a fail.

请查看我的代码:

<?php 
if(!mkdir($_SERVER['DOCUMENT_ROOT'].'/uploads/2017', 0777, true))
    {
        echo("echec");
    }
chmod($_SERVER['DOCUMENT_ROOT'].'/uploads/2017', 0777);
?>

父文件夹为"admin",其权限设置为755.

The parent folder is "admin" and it permissions are set to 755.

您有任何线索为什么这行不通吗?

Do you have any clue why this isn't working ?

我重新制作了它,并且起作用了,不知道问题出在哪里.

EDIT : I remade it and it worked, no clue what the problem was.

推荐答案

代码

mkdir('/2017', 0777, true)

创建文件夹2017是文件系统的根文件夹.

creates folder 2017 is a root folder of a file system.

始终将完整的路径设置为您的文件夹,例如:

Always set ethier full path to your folder, e.g.:

mkdir($_SERVER['DOCUMENT_ROOT'] . '/2017', 0777, true);
// or
mkdir('/var/www/mysite/2017', 0777, true);

或使用...定义正确的位置:

Or use . or .. to define proper location:

// folder will be created in a same directory 
// as a script which executes this code
mkdir('./2017', 0777, true);

// folder will be created in a directory up one level
// than a script which executes this code
mkdir('../2017', 0777, true);

因此,在您的情况下,很明显:

So, in your case it is obviously:

mkdir($_SERVER['DOCUMENT_ROOT'] . '/admin/2017', 0777, true);

这篇关于PHP mkdir();不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆