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
精彩评论