Tom Tom - 2 years ago 124
PHP Question

php set path using preg_match?

I'm creating a very simple file browser, and am trying to limit the path to be

, but NOT
it's self. (where ANYTHING can be any subfolder).

Currently I'm using:

$path = (strpos($path, '/local/') !== false) ? $path : "/local/ud";

But this accepts
as the path. The aim is if its not
then set it to

I've tried to use
and set it as
but again this allow access to

Is there any way to say the path can only be
while excluding
/local itself

Answer Source

This forces at least one letter after /

preg_match("/\/local\/\w.*/", $input, $output);

Edited to add \w to make sure you cant be at /local/ <- there is supposed to be a space after /

Maybe this is even better? "/\/local\/[\w|\d].*/" One letter or digit then anything

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download