Blue Sky
Blue Sky

Reputation: 827

php mkdir windows relative path

I want to create a directory on windows from a PHP script.

My script is in the www/Test directory of Apache and I want to create a folder (fold1) inside www/downloads directory.

Inside the script, I'm using:

$dirName = "../downloads/fold1";   
mkdir("{$dirName}");

If I use the full path of dirName like C:\Apache\www\downloads\fold1, it works fine.

But I want to use a relative path since this code will be sent to the client.

Upvotes: 4

Views: 7427

Answers (1)

ZeissS
ZeissS

Reputation: 12135

I would guess your current directory is different from your files folder, so you have to use a trick:

mkdir(dirname(__FILE__) . "/" . $relative_path);

dirname(__FILE___) returns the absolute path of your current php file. With this you can build an absolut path.

Upvotes: 11

Related Questions