How do I make sure a file path is within a given subdirectory?

前端 未结 3 1377
隐瞒了意图╮
隐瞒了意图╮ 2021-01-13 02:19

I want to make sure a file path set via query string does not go outside of the desired subdirectory. Right now, I am checking that:

  1. The path does not start w
3条回答
  •  北海茫月
    2021-01-13 02:52

    Call

    $path = realpath("sample/$path");
    

    Then check that the resulting path starts with the directory you're expecting.

提交回复
热议问题