Using the chmod() Function : chmod « File Directory « PHP






Using the chmod() Function

 
<?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);
?>
  
  








Related examples in the same category

1.Changing File Permissions and Ownership
2.Changing file permissions
3.chmod() function changes the mode of filename to permissions.