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

Zaiur Rahman zrahman at partex.net
Tue May 13 04:45:45 PDT 2003



 
-----Original Message-----
From: klutz-bounces at lists.horde.org
[mailto:klutz-bounces at lists.horde.org] On Behalf Of Ziaur Rahman
Sent: Tuesday, May 13, 2003 7:39 PM
To: klutz at lists.horde.org
Subject: [klutz] Driver file.php and trailing slash in the mkdir()


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 --- - - - 
 

-- 
klutz mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: klutz-unsubscribe at lists.horde.org




More information about the horde mailing list