Get the directory of a file in PHP

If you need to find the server path of a directory to do things like upload files, do FTP operations, file operations, etc...

This is how you can find the server path in PHP.

 


if (DIRECTORY_SEPARATOR=='/')
  $absolute_path = dirname(__FILE__).'/';
else
  $absolute_path = str_replace('\\', '/', dirname(__FILE__)).'/';


echo $absolute_path;

Keywords: php get directory, server path


Submit a Comment