tags:

views:

74

answers:

3

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');
+2  A: 
bool mkdir(string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context]]])

The $mode param is an integer, not a string. :)

Here's the example:

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

You must use:

mkdir('jigsaw/assets/images/jigsaw_image', 0777);
TiuTalk
+11  A: 

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

Ignacio Vazquez-Abrams
cheers bud! works like a charm
Drew
Oh, damn! I was convinced it was a masking problem.
bart
+1  A: 

http://php.net/manual/en/function.mkdir.php

The second argument is supposed to be an int, not a string. Take out the quotes.

Amber