This is really bad code. First you lowercase the whole file path ensuring that any uppercase path will break this code (as when you lowercase it you will then try to write along a non existant path). Next you seem to have forgotten that '.' and '..' are not the only directories you might find. Finally you should never print unescaped arbitrary strings in HTML.