简体   繁体   中英

mkdir(): Permission denied Permissions is set

I know there is a lot of answers for this already but it just doesn't work.

I am trying to make my php script to create a folder on my ubuntu apache server.

if (!@mkdir($url, 0700, true)) {
    $error = error_get_last();
    echo $error['message'];
}

Now I have changed the permission for www-data to 777 and www-data owns the folder var/www/html and all of the subdirectories.

Now what to do?

The $url I pass is /files/test3

I have tested with /files/test3/ as well but that doesn't work.

Edit:

This is how my files are sorted atm using tree这就是我的文件在 atm 中使用树排序的方式

You are trying to make a folder with an absolute path (/files/test3) which literally makes /files/test3 [which you probably do not own /files, and cannot make folders off / because you're not root], not /var/www/html/files/test3.

You can use __DIR__. '/'. $url __DIR__. '/'. $url __DIR__. '/'. $url or set $url to files/test3 instead.

Try this:

$url = '~/files/test3/';

if (!mkdir($url, 0700, true)) {
    $error = error_get_last();
    echo $error['message'];
}

Should create a folder files , with another folder test3 inside of it, in the home directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM