Posted By

chrisaiv on 12/23/09


Tagged

php file


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

nerdfiles
BrianCoyDesign
joethermal


PHP: File System Basics


 / Published in: PHP
 

Here are some ways to figure out what file or directory your script is loading from.

  1. <?php
  2.  
  3. //Provide the file name
  4. echo __FILE__ . "<br />";
  5.  
  6. //What line is this being executed
  7. echo __LINE__ . "<br />";
  8.  
  9. //Provide the directory name
  10. echo dirname( __FILE__ ) . "<br />";
  11.  
  12. //Does this file exist within the directory?
  13. echo file_exists( dirname( __FILE__ ) . "/basic.html" ) ? "yes" : "no";
  14.  
  15. //Find out if the directory exist?
  16. echo file_exists( dirname( __FILE__ ) ) ? "yes" : "no";
  17.  
  18. //Does this file exist?
  19. echo is_file( dirname( __FILE__ ) . "/basic.html" ) ? 'yes' : 'no';
  20.  
  21. //Does this directory exist?
  22. echo is_dir( dirname( __FILE__ ) ) ? 'yes' : 'no';
  23.  
  24. //Determine if this is a directory (version 2)
  25. echo is_dir( '..' ) ? 'yes' : 'no';
  26.  
  27. ?>

Report this snippet  

You need to login to post a comment.