Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 433
Blue Sky Avatar asked Sep 15 '25 12:09

Blue Sky


1 Answers

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.

like image 57
ZeissS Avatar answered Sep 17 '25 02:09

ZeissS