windows php mkdir windows相对路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2927294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php mkdir windows relative path
提问by Blue Sky
I want to create a directory on windows from a PHP script.
我想从 PHP 脚本在 Windows 上创建一个目录。
My script is in the www/Test
directory of Apache and I want to create a folder (fold1) inside www/downloads
directory.
我的脚本位于www/Test
Apache 目录中,我想在目录中创建一个文件夹 (fold1) www/downloads
。
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.
如果我使用 dirName like 的完整路径C:\Apache\www\downloads\fold1
,它工作正常。
But I want to use a relative path since this code will be sent to the client.
但我想使用相对路径,因为此代码将发送到客户端。
回答by ZeissS
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.
dirname(__FILE___)
返回当前 php 文件的绝对路径。有了这个,你可以建立一个绝对路径。