我有 root 擁有的檔案,我想使用chmod(). 但它給了我一個錯誤chmod(): Operation not permitted。
if (file_exists($filepath)) {
chmod($filepath, 0755);
}

如何chmod()在 php 中使用但檔案所有權是 root ?我可以在不更改檔案所有權的情況下實作這一目標嗎?
應用環境:
- PHP 7.1.33
- Code Igniter 3 框架
- 阿帕奇 2.4.6
- CentOS Linux 發行版 7.8.2003
任何答案表示贊賞,感謝之前。
編輯:
我已經運行ps aux | grep httpd,它只在串列中顯示 root 和 apache。

uj5u.com熱心網友回復:
由于檔案屬于 root 而不是 www-data,apache 將無權更改檔案的讀寫權限。您需要將檔案夾設定為由 www-data 擁有和寫入。
centOS 中的命令是
sudo chown -R apache:apache ./filepath
您需要 sudo 作為根所有者,并將檔案路徑替換為您的檔案夾名稱
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/536859.html
