// Windows absolute path $path = 'C:/xampp/htdocs/example.php'; // Linux absolute path $path = '/var/www/example.php';
//Relative path to a file in the same directory $path = 'example.php'; //Relative path to a file in a subdirectory $path = 'subfolder/example.php'; //Relative path to a file in a parent directory $path = '../example.php';
//Using __DIR__ $path = __DIR__ . '/example.php'; //Using dirname() $path = dirname(__FILE__) . '/subfolder/example.php';
//Using fopen() $fp = fopen('example.txt', 'r'); $content = fread($fp, filesize('example.txt')); fclose($fp); //Using file_get_contents() $content = file_get_contents('example.txt');Package/Library: PHP core