简体   繁体   中英

Warning: mkdir(): Permission denied in hostinger

I was trying to create directories automatically with php, with the mkdir() function.

<?php
session_start();

$domain = $_SESSION['domain'];
$mydomain = "/" . $domain;
echo $_SESSION['domain'] . " " . $mydomain . "<br />";
$mk = mkdir($mydomain, 0777, true);
if ($mk){
    echo "directory created";
}else{
    echo "directory no created";
}
?>

but it gave me back this error

[02-May-2021 09:19:41 UTC] PHP Warning:  mkdir(): Permission denied in /home/u950517783/domains/mydomain.host/public_html/website/createdir.php on line 7
[02-May-2021 09:22:28 UTC] PHP Warning:  mkdir(): Permission denied in /home/u950517783/domains/mydomain.host/public_html/website/createdir.php on line 7
[02-May-2021 09:22:30 UTC] PHP Warning:  mkdir(): Permission denied in /home/u950517783/domains/mydomain.host/public_html/website/createdir.php on line 7
[02-May-2021 09:22:31 UTC] PHP Warning:  mkdir(): Permission denied in /home/u950517783/domains/mydomain.host/public_html/website/createdir.php on line 7
[02-May-2021 09:22:32 UTC] PHP Warning:  mkdir(): Permission denied in /home/u950517783/domains/mydomain.host/public_html/website/createdir.php on line 7
[02-May-2021 09:22:32 UTC] PHP Warning:  mkdir(): Permission denied in /home/u950517783/domains/mydomain.host/public_html/website/createdir.php on line 7
[02-May-2021 09:22:36 UTC] PHP Warning:  mkdir(): Permission denied in /home/u950517783/domains/mydomain.host/public_html/website/createdir.php on line 7

how can i fix that? im using hostinger

You can try like below

<?php
 session_start();

 $domain = $_SESSION['domain'];
 $mydomain = "/" . $domain;
 echo $_SESSION['domain'] . " " . $mydomain . "<br />";

 $old = umask(0);
 $mk = mkdir($mydomain, 0777, true);
 umask($old);

  if ($mk){
      echo "directory created";
  }else{          
      chmod($mydomain, 0777);
  }
 ?>

if mkdir() Not worked, You need to change permissions using chmod()

https://www.php.net/umask

Use echo for example to look at the value of $mydomain and then use this command to give the right access

chmod 777 -R <directory name>

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