file_exists() PHP Filesystem Function Example

file_exists php filesystem function example - checks whether a file or directory exists or not

file-exists-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>file_exists php filesystem function example - checks whether a file or directory exists or not</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="file_exists php filesystem function example - checks whether a file or directory exists or not">
  <meta name="keywords" content="php, example, code, file, function, filesystem, filestream, file_exists, directory">
  <meta name="description" content="file_exists php filesystem function example - checks whether a file or directory exists or not">
  <style>
   h2, h4{background:orange; color:#000081;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h4{ padding:2px; margin:2px; font-size:18px;}
   p{padding:2px; margin:2px; color:#0099FF;}
   body{ background:#FFFFFD;}
  </style>
 </head>
 <body>
  <h2>file_exists php filesystem function example - checks whether a file or directory exists or not</h2>
  <pre>
   <?php
    /*
     -------------------------------------------------------------------------------------
     let say we have a file name called test.php in local server in some directory, now
     we would like to test whether it is exist or not by using php file_exists function.
     -------------------------------------------------------------------------------------
    */
    $filePathInDirectory = "C:\\xampp\\htdocs\\phpexamplecode\\test.php";
    echo "<h4>Output of filePathInDirectory in the browser</h4>";
    print "<p>$"."filePathInDirectory = {$filePathInDirectory}</p>";
    /*
     --------------------------------------------------------------
     using the file_exists php filesystem function check the file
     --------------------------------------------------------------
    */
    $file_exists = file_exists($filePathInDirectory);
    if($file_exists == true)
    {
     $FileExistString = "Yes, the given file is exist";
    }
    else
    {
     $FileExistString = "No, the given file is not exist";
    }
    echo "<h4>Output of file_exists in the browser for file</h4>";
    print "<p>$"."FileExistString = {$FileExistString}</p>";
    /*
     --------------------------------------------------------------------------------------------------
     we can also test whether a directory is exist or not by using php filesystem file_exists funciton
     --------------------------------------------------------------------------------------------------
    */
    $fileDirectory = "C:/xampp/htdocs/phpexamplecode/";
    $file_exists = file_exists($fileDirectory);
    if($file_exists == true)
    {
     $DirectoryExistString = "Yes, the given directory is exist";
    }
    else
    {
     $DirectoryExistString = "No, the given directory is not exist";
    }
    echo "<h4>Output of file_exists in the browser for directory check</h4>";
    print "<p>$"."fileDirectory = {$fileDirectory}</p>";
    print "<p>$"."DirectoryExistString = {$DirectoryExistString}</p>";
    /*
     -----------------------------------------------------------------------------------------------
     in windows both / and \ are used as directory separator, in php \ is used as escape character
     thus \\ means one \ character. it is used rapidly in professional programming.
     -----------------------------------------------------------------------------------------------
    */
   ?>
  </pre>
 </body>
</html>

file_exists php filesystem function example - checks whether a file or directory exists or not - output in the browser

 

Related Tutorial Examples

  1. Check Loaded Module in Apache Web Server
  2. Get Loaded Extensions in Apache Web Server
  3. curl_version() - cURL or Client URL Version Information
  4. Enable or Disable WSDL Cache :: soap.wsdl_cache_enabled
  5. Google Maps API Tutorial Geocoder Class Example
  6. Display Yahoo Weather RSS Feed PHP Class Example
  7. Trace Visitor's IP Address PHP Example
  8. 20 steps to make CakePHP Blog Project
  9. 19 Examples to Learn MySQL
  10. file_get_contents() PHP Filesystem Function Example

No comments:

Post a Comment

leave your comments here..