开发者

File path as PHP URL parameter

开发者 https://www.devze.com 2023-03-12 23:41 出处:网络
I have a PHP file that will be accepting several URL parameters, one of which is a local file path (c:\\users\\etc..).Whenever this parameter is read in, PHP makes it into double backslashes (c:\\user

I have a PHP file that will be accepting several URL parameters, one of which is a local file path (c:\users\etc..). Whenever this parameter is read in, PHP makes it into double backslashes (c:\users\etc..) which my upload code will not accept as a valid path. What can I do here开发者_开发技巧?

Thanks

-Jesse


First of all, avoid accepting paths in query string for security reasons. You may want to set include path in php.ini file instead.

You can replace double backslashes with single ones like this:

$myvalue = str_replace('\\\\', '\\', $original_path);

You specify \ twice to actually escape it while replacing.

Working Example


This sounds like a typical Magic Quotes-problem. You can disable them in different ways. As of PHP 5.3 they are deprecated und will be removed in PHP 6.


you can do

$newpath = str_replace("\\\\","\\",$oldpath);

or similary

$newpath = stripslashes($olpath);

note that the second one works depending on the magin_quotes setting in your php.ini

0

精彩评论

暂无评论...
验证码 换一张
取 消