Restructured code in present to find bug (bug vanished, but I don't see why). Made mkdir_p a little bit more fault tolerant.
Relative paths are wrong, and permissions are missing. Database support is missing.