I have a directory and a dynamic file name. Are there any functions I can use to make sure it is impossible to break out from the specified directory?
for example:
secure_path('/tmp/', 'file.txt') -> /tmp/file.txt
secure_path('/tmp/', '../file.txt') -> /tmp/file.txt
If you’re only working in the single directory and not subdirectories below you could do
Which should give you the filename at the end of any path given in input, and append it to the directory you wanted.