get_current_user() returns the OWNER of the php script - now we use posix functions...
[phpfspot.git] / phpfspot.class.php
index 4cdf3039541794ee1a4fe9550df2a7c440722321..579054d6ebd70a18caba3abd46612723c6e5474f 100644 (file)
@@ -23,6 +23,12 @@ class PHPFSPOT {
       $this->cfg = new PHPFSPOT_CFG;
 
       $this->db  = new PHPFSPOT_DB(&$this, $this->cfg->fspot_db);
+      
+      if(!is_writeable(dirname($this->cfg->phpfspot_db))) {
+         print dirname($this->cfg->phpfspot_db) .": directory is not writeable!";
+         exit(1);
+      }
+         
       $this->cfg_db = new PHPFSPOT_DB(&$this, $this->cfg->phpfspot_db);
       $this->check_config_table();
 
@@ -193,7 +199,7 @@ class PHPFSPOT {
       }
 
       if(!is_readable($orig_path)) {
-         $this->_warning("Photo ". $orig_path ." is not readable for user ". get_current_user() ."<br />\n");
+         $this->_warning("Photo ". $orig_path ." is not readable for user ". $this->getuid() ."<br />\n");
       }
 
       /* If the thumbnail doesn't exist yet, try to create it */
@@ -885,7 +891,7 @@ class PHPFSPOT {
       }
 
       if(!is_readable($full_path)) {
-         $this->_warning("File ". $full_path ." is not readable for ". get_current_user() ."\n");
+         $this->_warning("File ". $full_path ." is not readable for ". $this->getuid() ."\n");
          return;
       }
 
@@ -1313,6 +1319,18 @@ class PHPFSPOT {
 
    } // whatToDo()
 
+   private function getuid()
+   {
+      if($uid = posix_getuid()) {
+         if($user = posix_getpwuid($uid)) {
+            return $user['name'];
+         }
+      }
+   
+      return 'n/a';
+   
+   } // getuid()
+
 }
 
 ?>