skip to Main Content

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
This is how my files are sorted atm using tree

2

Answers


  1. 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 or set $url to files/test3 instead.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search