PHP mkdir(); not working

给你一囗甜甜゛ 提交于 2020-01-17 06:41:09

问题


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.

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

Please have a look at my code :

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

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.


回答1:


Code

mkdir('/2017', 0777, true)

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);



回答2:


Example #1 mkdir() example

<?php
mkdir("/path/to/my/dir", 0700);
?>


来源:https://stackoverflow.com/questions/42690561/php-mkdir-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!