I can’t find why does my Codeigniter not CHMOD specific directory to 777 from the controller, so looking for some advice on how to solve this.
I’m running centos 7, PHP 7.2
I have a controller with a location: public_html/application/controllers/users.php
And I need to CHMOD directory: public_html/uploads/whatverfolder/userfolder/
public function att() {
$uploaddir = 'uploads/whatverfolder/userfolder';
if (file_exists($uploaddir )) {
echo 'YES DIRECTORY EXIST'; // geting success
@chmod($uploaddir, FILE_WRITE_MODE); // -> not working
chmod($uploaddir, 0777, true); // -> not working
}
}
This is error I’m getting:
ERROR - 11th July 2019 10:10:24 --> Severity: Warning --> chmod(): Can not call chmod() for a non-standard stream /home/u7658/web/mydomain.com/public_html/application/controllers/users.php 1578
ERROR - 11th July 2019 10:10:24 --> Severity: Warning --> chmod(): Operation not permitted /home/u7658/web/mydomain.com/public_html/application/controllers/users.php 1585
Also, ownership of the folder to chmod is a root [0] (that’s correct)
Also, that folder has been created by CodeIgniter, by this code (directory has been created but with 775 permission, even when mkdir should create a directory with 777 permission.
$domainpath = "./uploads/domeny/".$ID."/";
// make folder
if (!file_exists($domainpath)) {
mkdir($domainpath, 0777, true);
}
I just missing something, thanks for the help!
2
Answers
The reason was that this specific directory has not been created by mkdir, that directory (due to migration) has been upload by FTP. So, I dont know why but If you upload on my server directory by FTP, then you are not allowed to chmod that directory by php, probably due to OWNER/GROUP perm. But my perm for that folder was root.. so still not sure why, but It's working now.
Try this, use
BASEPATH
from config to achive absolute path