Hello,

Is it possible to pass mkdir() a relative url instead of an absolute url? My hosting company decided to change the directory name for the root of a client's usr directory and I've had to update the functions accordingly. If possible I would rather not have functions hardwired to the usr root.

function create_folder($username)
{
	mkdir("/home/.this has been changed/username/domain.com/subdir/$username", 0755);
}

Thanks,

Jason

    This is the reason why [man]realpath/man can be a big help in situations with relative paths. If you define a root by saying:

    <?php
    
    $root = realpath('../../../mydir');

    Then the hosting company could move your site anywhere and as long as they don't muck with your structure, then you wouldn't have to worry.

      Just to be clear here, you can pass mkdir() a relative filesystem path, but you can not pass it any kind of URL. Depending on what you want to accomplish and where the script is running, you could use a relative path something like:

      mkdir("../subdir/$username", 0755);
      

      Along the lines of what bpat described above, you could make an absolute path as:

      mkdir($_SERVER['DOCUMENT_ROOT'] . "/subdir/$username", 0755);
      
        Write a Reply...