PHP code mkdir ('images', '0777') creates a folder with 411 permissions! What for?

I could swear it worked yesterday. However, now the code below destroys the folder without problems, but creates a new folder with 411 permissions, when it should be 777. My code did it yesterday.

The purpose of this is to fasten the folder, deliver it, delete the images, and then create a new directory for the images.

Can someone tell me what I'm doing wrong or what should I do? Thanks

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');
+5
source share
5 answers

Because you should use an octal literal 0777, not a number-per-string "0777", which is actually 01411in octal format.

+29
source

, 0777.

mkdir("infosheets/c/" , 0777);

​​ 0755!

:

$test="infosheets/c/";
mkdir($test);
chmod($test,0777);

0777. ! !

+6
bool mkdir(string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context]]])

$mode , .:)

:

<?php
mkdir("/path/to/my/dir", 0700);
?>

:

mkdir('jigsaw/assets/images/jigsaw_image', 0777);
+2

, , , , [].

, ! -, 000 111 111 100, 8- 0774.

3 "rwx", "" "" "", "on" , "".

, , 8 , 255 (2 ^ 8) -1 . , , unix.

( 10) , , (https://en.wikipedia.org/wiki/Endianness)

32- 00000000 00000000 00000001 11111100 aka 508, , . , .

, small-int, 16 32:), ...

:) google https://en.wikipedia.org/wiki/Filesystem_permissions

it simply means contextual information to understand what is happening and how the next solution will work.

TL DR

octdec("0774")

doing the trick

+1
source

All Articles