Dynamic Filesystem: problem with --> / in file paths

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
X_Citer
Forum Newbie
Posts: 10
Joined: Thu Jul 12, 2007 11:18 pm

Dynamic Filesystem: problem with --> / in file paths

Post by X_Citer »

Hi, I am creating a dynamic filesystem for my very small web hosting company. It uses a username cookie to access a specific folder and for the life of me i cannot make the \ at the end of the file paths work correctly without sending it on a none existant file path. PLEASE HELP!!

$folder=$_COOKIE['username'];
$path="C:\Program Files\Cerberus\FTP Clients\.".$folder;
$dir_handle= opendir($path) or die("Unable to open FTP client");
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The folders are have a leading dot?
X_Citer
Forum Newbie
Posts: 10
Joined: Thu Jul 12, 2007 11:18 pm

Post by X_Citer »

No but you cant put a \" it throws an error every time... that's the problem... it needs that slash at the end.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

A \ is also an escape character, so it needs to be escaped...

Code: Select all

$folder=$_COOKIE['username'];
$path="C:\\Program Files\\Cerberus\\FTP Clients\\".$folder;
$dir_handle= opendir($path) or die("Unable to open FTP client");
I believe that should work for you. I haven't ran across this in ages though, as I don't run scripts in windows.
X_Citer
Forum Newbie
Posts: 10
Joined: Thu Jul 12, 2007 11:18 pm

Post by X_Citer »

Yep that solved it fine.. thanks for all the help :)
Post Reply