PHP以用戶Apache身份運行。您的FTP帳戶正在以用戶'fpadmin'運行。這就是業主不同的原因。你有沒有試過chown()php函數(http://php.net/manual/en/function.chown.php)?這將更改文件/目錄的所有者。
乾杯
唉,我先下投票。這刺激..雖然這是一個愚蠢的回答..
好吧,所以我想了解你的問題/複製你的錯誤。這是我試過的,這裏是我的結果。希望它至少對你有一些用處。
我有以下目錄結構:
/var/www/public_html/test (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/index.php (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/ftp_owned.file (chmod = 644 (default), owned by 'ftpuser')
然後在index.php文件我有以下代碼:
mkdir("./downvoted");
chmod("./downvoted", 0777);
$h = fopen("./i_am_so.sad", "x+");
fwrite($h, "attempting to redeem myself");
fclose($h);
rename("./i_am_so.sad", "./downvoted/i_am_so.sad");
rename("./ftp_owned.file", "./downvoted/ftp_owned.file");
在一個新的目錄結構得到的:
/var/www/public_html/test (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/index.php (chmod = 777 via SSH, owned by 'ftpuser')
/var/www/public_html/test/downvoted (chmod = 0777 via PHP, owned by 'apache')
/var/www/public_html/test/downvoted/i_am_so.sad (permissions = 644 (default), owned by 'apache')
/var/www/public_html/test/downvoted/ftp_owned.file (permissions = 644 (default), owned by 'ftpuser')
仍然難過,因爲我無法重現錯誤,也無法兌現自己。希望你可以發佈你收到的錯誤(許可被拒絕?)或指出我的實驗與你的應用程序有什麼不同。
謝謝!我將php.ini錯誤報告設置爲E_ALL,這正是返回的錯誤。奇怪的是,我有PHP(「apache」用戶)創建目錄和文件(或上傳),但由於某種原因,文件夾和文件被分配給不同的用戶... – Nick 2010-09-16 19:02:46