Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

I could swear this was working yesterday. Now however the code below destroys the folder with no problem but creates a new folder with 411 permissions when it should be 777. My code was doing this yesterday.

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

Can someone tell me what I am doing wrong or what i should be doing? 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');
like image 331
Drew Avatar asked Feb 12 '10 11:02

Drew


2 Answers

Because you should be using the octal literal 0777, not the number-in-a-string "0777", which is actually 01411 in octal.

like image 55
Ignacio Vazquez-Abrams Avatar answered Nov 11 '22 13:11

Ignacio Vazquez-Abrams


I had kinda same problem, but even after removing quotes, the permission will not be set to 0777.

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

but the created folder is set to 0755!

thats the solution:

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

you should first make the folder and than set it's permission to 0777. they should be done separately for an unknown reason to me! strange!

like image 39
Omidoo Avatar answered Nov 11 '22 11:11

Omidoo