mkdir does not create the directory

Asked

Viewed 1,197 times

-1

Even though I have permission, it does not create the directory and returns "not created".

<?php
$diretorio = 'C:/xampp/htdocs/LuckTor/arquivos/';
if (mkdir($diretorio . 'teste/', 777, true)) {
    echo 'criou';
} else {
    echo 'não criou';
}

echo 'q';
?>
  • No other error appears? Just "No criouq"?

  • @Asurakhan Before appeared in English "This directory does not exist or was not found in", but now appears nothing more.

  • Try checking the error message thus.

  • it seems that the error has nothing to do with this piece of code.

  • The error returns that I am not allowed to create the folder, thanks for the help.

  • 1

    mkdir will not create a file but a directory, it seems to me is user permission since the function mkdir returns true or false if the path exists in full.

  • Lucas, adjust more details of the answer, check if you can...

Show 2 more comments

1 answer

0


Lucas,

The command mkdir has the following path, mode and recursive parameters.

  • Question: The path C:/xampp/htdocs/Lucktor/arquivos/ exite?

If using Windows the mode parameter is ignored, try this way:

mkdir ("C:/opt/xampp/htdocs/LuckTor/arquivos/teste");

If you have used Linux, try to do so:

$oldmask = umask(0);
mkdir ("/opt/xampp/htdocs/LuckTor/arquivos/teste", 0777, true);
umask ($oldmask);

The first line changes umask to zero while storing the previous one in $ oldmask. The second line causes the directory to use the desired permissions. The third line restores umask to what it was originally.

In this example it is indispensable that the variable safe_mode is disabled. To change the safe_mode directive of a domain in Resell Linux, go to Plesk, click on the domain, go to "Configuration" and, on the line (PHP 'safe_mode' on), uncheck only the "ON".

More information:

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

http://www.php.net/manual/en/function.umask.php

https://stackoverflow.com/questions/3997641/why-cant-php-create-a-directory-with-777-permissions

  • It didn’t work trying this way.

  • Lucas, adjust more details of the answer, check if you can...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.