[klutz] Driver file.php and trailing slash in the mkdir()

Ziaur Rahman zia at qalacom.com
Tue May 13 04:38:33 PDT 2003


Hi Guys,
 
I was just testing the klutz and found that it cannot create the
directory under the base directory to store the comics because of a
trailing slash in the subdirectory name if PHP safe_mode is on.
 
Here is what I mean:
 
/**
     * The format for the various subdirectories.
     * WARNING: DO NOT CHANGE THIS!
     *
     * @var string $subdir
     */
    var $subdir = 'Ymd/';
 
....
 
$dir = $this->basedir . date($this->subdir, $date);
 
        if (!file_exists($dir)) {
            mkdir($dir, 0700);
        } elseif (!is_writable($dir)) {
            return false;
        }
 
Now, this fails if PHP's safe_mode is on.
 
-------------- excerpt form php.net --------
charlie at brown dot org
22-Feb-2003 05:53	 
	
Beware of trailing slashes with mkdir() under safe_mode
With safe_mode on,
This doesn't work:
mkdir("/home/sites/site99/web/mydir/",0770);
This does work:
mkdir("/home/sites/site99/web/mydir",0770);
With safe_mode off they both work. I tested on PHP v 4.1.2 and 4.2.3	
------------------------------------------------------
 
The following patch did the job for me:
 
--- file.php.orig       Tue May 13 19:00:34 2003
+++ file.php    Tue May 13 19:32:38 2003
@@ -350,7 +350,10 @@
         $dir = $this->basedir . date($this->subdir, $date);
 
         if (!file_exists($dir)) {
-            mkdir($dir, 0700);
+           if (substr($dir, -1) == '/') {
+               $mdir = substr($dir, 0, strlen($dir) - 1);
+           }
+            mkdir($mdir, 0700);
         } elseif (!is_writable($dir)) {
             return false;
         }
 
 
But, I am not sure whether this is the ideal way of coding or not
according to Horde's coding standard.
 
 
Regards,
 
Zia
 

- - - --- Quote of the moment --- - - - 

More than 400,000 Americans are arrested each year on marijuana charges.


- - - --- Quote of the moment --- - - - 
 


More information about the klutz mailing list