PHP/File Directory/chmod
Содержание
Changing file permissions
<source lang="html4strict">
<?php chmod("/home/user/secrets.txt",0400); ?>
</source>
Changing File Permissions and Ownership
<source lang="html4strict">
<?
chmod("/var/www/myfile.txt", 0777); chmod("/var/www/myfile.txt", 0755); if (chown("myfile.txt", "sally")) { print "File owner changed.\n"; } else { print "File ownership change failed!\n"; }
?>
</source>
chmod() function changes the mode of filename to permissions.
<source lang="html4strict">
Its syntax is: int chmod (string filename, int permissions) The permissions must be specified in octal mode. <?
chmod ("data.txt", 0766); // This will work
?>
</source>
Using the chmod() Function
<source lang="html4strict">
<?php
$fr = @fopen("data.txt", "w"); if(!$fr) { chmod("data.txt", 0722); $fr = @fopen("data.txt", "w"); if(!$fr) { echo "Error: Couldn"t open data.txt (chmod attempted)"; exit; } } fputs($fr, "Write Successful!"); fclose($fr);
?>
</source>