Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在父目录中创建文件夹?_Php_Mkdir - Fatal编程技术网

Php 如何在父目录中创建文件夹?

Php 如何在父目录中创建文件夹?,php,mkdir,Php,Mkdir,我的php脚本位于/var/www/html/users/dev中。我需要在/var/www/images/中创建一个文件夹,类似于/var/www/images/test/test/并将一些图像存储在这里 但当我尝试使用mkdir$file_dir,0777;其中$file_dir为/var/www/images/test/test/i时收到一个错误: 警告:mkdir:var/www/html/users/dev/classes/sites.class.php中没有这样的文件或目录 因为/v

我的php脚本位于/var/www/html/users/dev中。我需要在/var/www/images/中创建一个文件夹,类似于/var/www/images/test/test/并将一些图像存储在这里

但当我尝试使用mkdir$file_dir,0777;其中$file_dir为/var/www/images/test/test/i时收到一个错误:

警告:mkdir:var/www/html/users/dev/classes/sites.class.php中没有这样的文件或目录

因为/var/www/images/test不存在,所以不能使用mkdir/var/www/images/test/test

您可以将$recursive指定为TRUE,它将起作用,如下所示:

mkdir$file_dir,0777,TRUE

试试看

mkdir($file_dir, 0777, true);
第三个参数“recursive”允许您指定一个将创建所有目录的路径。如果不这样做,则只会创建最后一个目录“test”,并且在此之前必须存在整个路径


这一点非常清楚。

如果是Linux,则您首先对父目录设置了权限

sudo chmod -R 777 /path of ur directory.

权限或必须将true设置为第三个参数才能递归创建它。如果使用windows