Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (2)

Powered by Vanilla. Made with Bootstrap.
Check if folder/file is readable/writable

  • Here is a simple method on how to check if a file or a folder is readable / writable.



    <?php
    //Author: Anon2011
    //Created: 22/Feb/11
    //Purpose: To check whether file or is writeable/readable.

    echo '<form action=\"permissions.php\" method=\"POST\"/>
    Path and File or Folder to check : <input type=\"text\" name=\"check\" size=\"50\" />
    <input type=\"submit\" value=\"Check permissions\" />
    </form>';
    if(!isset($_POST['check']))
    {
    echo '<br/> Example: C:\file.txt or C:\folder';
    }

    if(isset($_POST['check']))
    {
    if(is_readable($_POST['check']))
    {
    echo $_POST['check']. \" is readable.<br/>\";
    }
    else
    {
    echo $_POST['check']. \" is NOT readable.<br/>\";
    }
    if(is_writable($_POST['check']))
    {
    echo $_POST['check']. \" is writable.<br/>\";
    }
    else
    {
    echo $_POST['check']. \" is NOT writable.<br/>\";
    }

    }
    ?>


    Output

    c:\debug.txt is readable.
    c:\debug.txt is writable.

    c:\Windows is readable.
    c:\Windows is writable.

    C:\Non-Existant-File.txt is NOT readable.
    C:\Non-Existant-File.txt is NOT writable.

    C:\Non-Existant-Folder is NOT readable.
    C:\Non-Existant-Folder is NOT writable.
  • Xin
    Posts: 3,251
    Nice simple code good job.
    Xin