Search code examples
phpwebserver

mkdir() not creating directory on web server even full path is specified


Please somebody help me, I want to create a folder 'uploads' in 'httpdocs' where my index.php file is placed, I am using Windows hosting with Plesk on Goddady. I went through available content on web but couldn't fix the issue, I am not very good with web servers. I have tried many solutions like full path specification, read - write permission, recursive directory creation using true/false etc but didn't work. It is working on my local server but not on web server. - Thanks in advance.

$path ="/PleskVhosts/abccat.in/httpdocs/uploads";
or 
$path ="G:/PleskVhosts/abccat.in/httpdocs/uploads";
or 
$path ="/httpdocs/uploads";  or $path ="/uploads";

mkdir($path, 0777, true);

I tried above all paths one by one, but didn't work. It is returning nothing as well. The full path for 'httpdocs' is G:/PleskVhosts/abccat.in/httpdocs. Any help? Thanks.


Solution

  • PHP docs for mkdir() say that the mode is ignored on windows.

    You may want to alter the permissions for the folders using chmod();

    http://php.net/manual/en/function.mkdir.php

    http://php.net/manual/en/function.chmod.php

    Don't forget to set your permission back after you create your file.

    chmod($folderPath, 0777); //<--This path would be for the folder you want your file in. 
    //You may have to do the chmod() for every folder all the way up to you target folder. 
    mkdir($filePath, 0777, true);
    chmod($folderPath, 'mode'); //<---Put in the mode you need it to be. Do this for any folder you previously changed.
    

    Try that and see if it helps.