PHP代码mkdir('images','0777')创建一个具有411权限的文件夹!为什么?

Dre*_*rew 6 php

我发誓昨天工作了.然而,现在下面的代码破坏文件夹没有问题,但创建一个具有411权限的新文件夹应该是777.我的代码昨天这样做.

这样做的目的是压缩文件夹,传递文件夹,删除图像,然后为图像创建新目录.

有人能告诉我我做错了什么或我应该做什么?谢谢

function delete_directory($dirname) {
   if (is_dir($dirname))
      $dir_handle = opendir($dirname);
   if (!$dir_handle)
      return false;
   while($file = readdir($dir_handle)) {
      if ($file != "." && $file != "..") {
         if (!is_dir($dirname."/".$file))
            unlink($dirname."/".$file);
         else
            delete_directory($dirname.'/'.$file);     
      }
   }
   closedir($dir_handle);
   rmdir($dirname);
   return true;
}

$directoryToZip="jigsaw/"; // This will zip all the file(s) in this present working directory

$outputDir="/"; //Replace "/" with the name of the desired output directory.
$zipName="jigsaw.zip";

include_once("createzipfile/CreateZipFile.inc.php");
$createZipFile=new CreateZipFile;

/*
// Code to Zip a single file
$createZipFile->addDirectory($outputDir);
$fileContents=file_get_contents($fileToZip);
$createZipFile->addFile($fileContents, $outputDir.$fileToZip);
*/

//Code toZip a directory and all its files/subdirectories
$createZipFile->zipDirectory($directoryToZip,$outputDir);

/*
$rand=md5(microtime().rand(0,999999));
$zipName=$rand."_".$zipName;
*/
$fd=fopen($zipName, "wb");
$out=fwrite($fd,$createZipFile->getZippedfile());
fclose($fd);
$createZipFile->forceDownload($zipName);

@unlink($zipName);
delete_directory('jigsaw/assets/images/jigsaw_image');

mkdir('jigsaw/assets/images/jigsaw_image','0777');
Run Code Online (Sandbox Code Playgroud)

Ign*_*ams 31

因为你应该使用八进制文字0777,而不是字母数字"0777",实际上01411是八进制.


Omi*_*doo 6

我有同样的问题,但即使删除引号后,权限也不会设置为0777.

mkdir("infosheets/c/" , 0777);
Run Code Online (Sandbox Code Playgroud)

但创建的文件夹设置为0755!

这就是解决方案:

$test="infosheets/c/";
mkdir($test);
chmod($test,0777);
Run Code Online (Sandbox Code Playgroud)

你应该首先制作文件夹,然后将它的权限设置为0777.它们应该由于一个未知的原因单独完成!奇怪!