function &getAlbumFromSectionPath($sectionType, $section_path) { // STATIC STRING METHOD
global ${$sectionType . 'LocationPath'};
$fileNameWithoutSection = preg_replace('/^' . str_replace('/', '\\/', ${$sectionType . 'LocationPath'}) . '(.*)$/', '$1', $section_path);
print_r("fileNameWithoutSection = $fileNameWithoutSection<P>");
$album = preg_replace('/^\/([^\/]+)\/[^\/]+$/', '$1', trim($fileNameWithoutSection));
print_r("album = $album<P>");
return $album;
}
This class method must extract a directory name, if found, from a full path to a file. The path will be structured in UNIX fashion as follows:
/path/to/my/file.ext
The class method will look to see if a subfolder found immediately before the "file.ext" file is found, if so, extract it, otherwise, return null.
Consider this:
/var/www/html/phillip/album1/image1.jpg
album = "album1"
/var/www/html/phillip/image2.jpg
album = ""
If you see the pattern, then you can help. Right now, this method will fail if your path is like this:
/var/www/html/phillip/image2.jpg
Because there is no album, however, album returns "/image2.jpg" which is entirely wrong. What do I do?
Thanx
Phil