windows 无法使用 mkdir 创建文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1324462/
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
Can't create a folder with mkdir
提问by KdgDev
Environment info:
*Windows Vista
*PHP 5.2.9-2
环境信息:
*Windows Vista
*PHP 5.2.9-2
I'm working on a project. Let's say it's name simply "project". My php files meant for user-interaction will be found at
我正在做一个项目。假设它的名称只是“项目”。我用于用户交互的 php 文件位于
project/file.php
项目/文件.php
Now, I have a database behind this and some maps, which contain classes and configuration files in general. There is also a map for the users, in which I store images they might upload. For instance:
现在,我在这背后有一个数据库和一些映射,它们通常包含类和配置文件。还有一张供用户使用的地图,我将他们可能上传的图片存储在其中。例如:
project/files/Users/0/profilePic.jpg
项目/文件/用户/0/profilePic.jpg
The number corresponds with the user_id in the database.
该数字与数据库中的 user_id 相对应。
My register.php
file contains this line of code:
我的register.php
文件包含这行代码:
mkdir('/files/Users/'.$id)
The $id
variable is the biggest id number in the database, plus 1.
该$id
变量是在数据库中最大的ID号,加1。
But it won't work. I checked the folders, I have both read and write permissions(I am admin on my machine).
但它不会工作。我检查了文件夹,我有读写权限(我在我的机器上是管理员)。
What am I doing wrong?
我究竟做错了什么?
Note: the right to tell me there's a better way to organize this reserved to those who can give me a helpful answer. :P
注:告诉我有更好的组织方式的权利保留给那些可以给我一个有用答案的人。:P
回答by Mark L
What about this?
那这个呢?
mkdir('c:/files/Users/'.$id)
回答by Randy
Couple of possibilities:
几种可能性:
- Lose the first / since that gives an absolute path and you're looking to make a relative path -- so mkdir('files/Users/'.$id)
- Does files/Users already exist (i.e., is there already user 0, user 1, etc.)? If not, you'll need to make them first or do mkdir('files/Users/'.$id, 077, true) to recursively create the directories.
- 失去第一个 / 因为它给出了一个绝对路径,而你正在寻找一个相对路径——所以 mkdir('files/Users/'.$id)
- 文件/用户是否已经存在(即,是否已经存在用户 0、用户 1 等)?如果没有,您需要先创建它们或执行 mkdir('files/Users/'.$id, 077, true) 递归创建目录。
回答by KdgDev
In windows, a path does not start with '/' but with a drive letter. Just remove the first slash (so '/files/users/' becomes 'files/users/').
在 Windows 中,路径不是以“/”开头,而是以驱动器号开头。只需删除第一个斜杠(因此'/files/users/' 变为'files/users/')。
Further, what Mark said.
此外,马克所说的。
回答by MANCHUCK
PHP states that it makes the best attempt at converting the / between systems. by doing:
PHP 声明它在系统之间转换 / 方面做出了最好的尝试。通过做:
mkdir('/files/users');
Confused PHP into thinking it was on a *NIX system. By setting the root to c:, it was now able to properly parse the parameter and deduce that it was a windows system
使 PHP 误以为它是在 *NIX 系统上。通过将 root 设置为 c:,它现在能够正确解析参数并推断它是一个 windows 系统