This simple PHP function accepts a URL string and returns the directory:
function getDirFromFilePath($file) {
$temp = explode('/', $file);
array_pop($temp);
return implode('/', $temp);
}
Example:
Input: http://www.domain.com/directory/filename.jpg
Output: http://www.domain.com/directory
Just wondering if there is a more efficient way to perform this, perhaps like a regex would?
You can just use
dirname(), which works with URLs too: