php修改文件權(quán)限
在php中修改文件權(quán)限,可以通過使用php中“chmod()”函數(shù)進(jìn)行權(quán)限修改
chmod說明和語法
chmod會嘗試將 filename 所指定文件的模式改成 mode 所給定的。
chmod ( string $filename , int $mode ) : bool
chmod參數(shù)
filename:文件的路徑。
mode:
注意 mode 不會被自動(dòng)當(dāng)成八進(jìn)制數(shù)值,而且也不能用字符串(例如 "g+w")。要確保正確操作,需要給 mode 前面加上 0:
<?php chmod("/somedir/somefile", 755); // 十進(jìn)制數(shù),可能不對 chmod("/somedir/somefile", "u+rwx,go+rx"); // 字符串,不對 chmod("/somedir/somefile", 0755); // 八進(jìn)制數(shù),正確的 mode 值 ?>
mode 參數(shù)包含三個(gè)八進(jìn)制數(shù)按順序分別指定了所有者、所有者所在的組以及所有人的訪問限制。每一部分都可以通過加入所需的權(quán)限來計(jì)算出所要的權(quán)限。數(shù)字 1 表示使文件可執(zhí)行,數(shù)字 2 表示使文件可寫,數(shù)字 4 表示使文件可讀。加入這些數(shù)字來制定所需要的權(quán)限。有關(guān) UNIX 系統(tǒng)的文件權(quán)限可以閱讀手冊“man 1 chmod”和“man 2 chmod”。
<?php // Read and write for owner, nothing for everybody else chmod("/somedir/somefile", 0600); // Read and write for owner, read for everybody else chmod("/somedir/somefile", 0644); // Everything for owner, read and execute for others chmod("/somedir/somefile", 0755); // Everything for owner, read and execute for owner's group chmod("/somedir/somefile", 0750); ?>
chmod返回值
成功時(shí)返回 TRUE, 或者在失敗時(shí)返回 FALSE。