Hello,
i recently fell into trouble while extending a few Spl-Classes
(SplFileInfo, RecursiveDirectoryIterator ...) for implementing a so
called "filemanager".
In short: You specify a filebase-root-directory (e.g. /home/www/cms/
public/filebase/ =note the slash "/" at the end of my path). My
filemanger-Class creates FileMangerFile-Instances (extending
SplFileInfo-Objects) for each directory and file under the above shown
path. It also creates an FileManagerFile-Instance of the "root-path"
to the filemanger-directory itself.
The Problem:
new SplFileInfo(/home/www/cms/public/filebase/)->getFilename() returns
empty value
new SplFileInfo(/home/www/cms/public/filebase)->getFilename() returns
"filebase"
SplFileInfo::getBasename() seems not to be documented nor implemented
yet (???), i have not found ressources for that. I would expect that
getBasename() "automagickally" delivers the filename of the
SplFileInfo-Object, beside beeing a folder, a file, a symlink ... An
Example:
getBaseName(/home/hans/wurst/käse.jpg")=>käse.jpg
getBaseName(/home/hans/wurst/) =wurst
getBaseName(/home/hans/wurst)=wurst
But it doesn't, obviously SplFileInfo::getBaseName() implements the
same logic as SplFileInfo::getFileName()
This is a real Problem, because internally i calculate absolute and
relative paths for using in internal file-operations (rmdir("/home/www/
cms/public..."), mkdir etc) but also for using in my view-layer (<img
src="/filebase/folder/image.jpg").
To calculate a relative pathname, i simply make a preg_replace with
$_SERVER[DOCUMENT_ROOT] on SplFileInfo::getPathName()
BUT: This will not work if you dont have a strict "trailing-slash"-
convention, or on the other hand i had to implement much "magic
trailing slash logic overhead" - and i simply want to avoid this.
So, my question is not to solve a special logic or syntactic question,
i rather want to inquire if there are some "best-practice-workflows"
to parallelly deal with internal/external, relative/absolute filenames
and how to deal with trailing slashes?
Thanks in advance,
der Johannes
(didn't get the point? Thats not your problem but a result of my bad
englisch ... sorry :((