regular expression
| From: | Galkov Vladimir | Date: | Thu, 01 Nov 2001 09:39:25 +0000 |
| Subject: | regular expression | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-73126@lists.php.net to get a copy of this message | ||
Need to remove all "../" "/.." from user inputing string to prevent him
walking and creating files&directories where I don't whant see them/him...
The string:
$path =
eregi_replace('([..]{2,})|([./]{2})|([../]{3,})|([/.]{2})|([/..]{3})', '',
$path);
works good with any combinations ( ../../..qwert.txt => qwert.txt) untill
somth like "/../asd/../qwert.txt" will be entered ... (/../asd/../qwert.txt
=> asdqwert.txt).
So the qwestion is how upgrade regular expression to remove all this
correctly (with all entered directory names but NOT assigned their names to
file name...
Must do the operation:
/../asd/......../qwert.txt => qwert.txt
but not => /asd/qwert.txt or asdqwert.txt.ru
or
/................../asd/../qwert.txt.ru => qwert.txt.ru
but not => /asd/qwert.txt.ru or asdqwert.txt.ru
Thanks.