chmod() Access Permission PHP Filesystem Function

chmod php filesystem function example - change file mode of the given file in some directory

chmod-php-filesystem-function-example.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>chmod php filesystem function example - change file mode of the given file in some directory</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="chmod php filesystem function example - change file mode of the given file in some directory">
  <meta name="keywords" content="php, example, code, file, function, filesystem, filestream, chmod, directory">
  <meta name="description" content="chmod php filesystem function example - change file mode of the given file in some directory">
  <style>
   h2, h4{background:orange; color:#000083;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h4{ padding:2px; margin:2px; font-size:18px;}
   p{padding:2px; margin:2px; color:#0099FD;}
   body{ background:#FFFFFB;}
  </style>
 </head>
 <body>
  <h2>chmod php filesystem function example - change file mode of the given file in some directory</h2>
  <pre>
   <?php error_reporting (1);
    /*
     -------------------------------------------------------------------
     let say we have a file name called test.php in local server,
     we would like to change the mode of the file by using php chmod function.
     -------------------------------------------------------------------
    */
    $fileInDirectory = "http://127.0.0.1/phpexamplecode/test.php";
    echo "<h4>Output of fileInDirectory in the browser</h4>";
    print "<p>$"."fileInDirectory = {$fileInDirectory}</p>";
    /*
     ------------------------------------------------------------------------------------
     now we want to allow read & write permission for owner and read permission for 
     everybody else (accessMode = 0644 ) by using php filesystem chmod function
     ------------------------------------------------------------------------------------
    */
    $accessMode = "0644";
    chmod($fileInDirectory, $accessMode);
    echo "<h4>Output of accessMode in the browser</h4>";
    print "<p>$"."accessMode = {$accessMode}, read & write permission for owner and read permission for everybody else</p>";
    /*
     ------------------------------------------------------------------------------------
     now we want to allow everything for owner and read & execute permission for others
     (accessMode = 0755 ) by using php filesystem chmod function
     ------------------------------------------------------------------------------------
    */
    $accessMode = "0755";
    chmod($fileInDirectory, $accessMode);
    echo "<h4>Output of accessMode in the browser</h4>";
    print "<p>$"."accessMode = {$accessMode}, everything for owner and read & execute permission for others</p>";
    /*
     ---------------------------------------------------------------------------------------
     this function rapidly used in professional programming to change file mode on the fly
     (dynamically) by programming
     ---------------------------------------------------------------------------------------
    */
   ?>
  </pre>
 </body>
</html>

chmod php filesystem function example - change file mode of the given file in some directory - output in the browser

 

Related Tutorial Examples

  1. Trace Visitor's Browser & Operating System Information
  2. SERVER IP Address? - HTTP HOST PHP Server Variable Example
  3. SERVER ADMIN? - HTTP HOST PHP Server Variable Example
  4. Request Information? - REQUEST URI PHP Server Variable Example
  5. Referer Website Information? - HTTP REFERER PHP Server Variable Example
  6. Website Hosting Information? - SERVER NAME PHP Server Variable Example
  7. Website Host PORT Information? - SERVER PORT PHP Server Variable Example
  8. 19 Examples to Learn MySQL
  9. file_exists() PHP Filesystem Function Example
  10. 20 steps to make CakePHP Blog Project

No comments:

Post a Comment

leave your comments here..