Skip to content

Instantly share code, notes, and snippets.

View ajmedway's full-sized avatar
💭
Available for work...

Alec Pritchard ajmedway

💭
Available for work...
View GitHub Profile
@jasdeepkhalsa
jasdeepkhalsa / get-current-dir.php
Last active January 25, 2016 14:44
Get the current file's public directory path (URL) in PHP
<?php
function get_current_dir(){
$file = realpath(dirname(__FILE__)); // Current file path
$patt = '/\/path\/to\/public\/directory/'; // Regex pattern for all non-public directories
$url = preg_replace($patt,'', $file); // Take out those non-public directories
return $url . '/'; // Return the URL with a trailing slash
}
/**
* This function may be useful for occasions where you need to call a file in PHP included in the same directory