/**
  * Sets the folder where sessions should be saved, in case we'd like to save
  * them somewhere else. This class will check the config parameter <b>session_save_path</b>: if
  * it's not empty, it will use its value as the name of the folder where sessions should be saved, and it
  * will also take care of creating the folder if it does not exist. If the folder exists but it cannot
  * be read, it will throw an exception and quit (because this is a big issue)
  * If the value of this parameter is empty, it will not do anything and use PHP's default settings for this.
  *
  * @static
  */
 function setSessionSavePath()
 {
     $config =& Config::getConfig();
     $sessionFolder = $config->getValue("session_save_path");
     // do we need to do anything if we are using the default
     // session path?  PHP defaults to /tmp/, so there isn't
     // anything to do
     if (isset($sessionFolder)) {
         if (!File::exists($sessionFolder)) {
             // create folder with only user permissions
             // since we want to protect the session data
             if (!File::createDir($sessionFolder, 0700)) {
                 throw new Exception("Sessions should be " . "saved in {$sessionFolder} but it " . "doesn't exist and I can't create it!");
                 die;
             }
         }
         // check if the folder is accessible
         if (!File::isReadable($sessionFolder) || !File::isWritable($sessionFolder)) {
             if (!File::chMod($sessionFolder, 0700)) {
                 throw new Exception("Sessions should be " . "saved in {$sessionFolder} but it is " . "not accessible!");
                 die;
             }
         }
         // if everything ok, we can continue...
         session_save_path($sessionFolder);
     }
     return true;
 }
 /**
  * the method above works only with files that have been uploaded while
  * this one works with files that are anywhere. It will take care of copying
  * the file to the right destination folder and so on
  *
  * @param ownerId The id of the owner of this file
  * @param albumId The album id to which the
  * @param fileName full path and name to the file that we're trying to store
  */
 function storeFile($resourceId, $ownerId, $fileName, $mode = RESOURCE_STORAGE_STORE_COPY)
 {
     // check that the folders exist
     if (!$this->_checkBaseStorageFolder()) {
         return false;
     }
     if (!$this->_checkUserStorageFolder($ownerId)) {
         return false;
     }
     // new name for the file
     $fileParts = explode(".", $fileName);
     $fileExt = $fileParts[count($fileParts) - 1];
     $destFile = "{$ownerId}-{$resourceId}.{$fileExt}";
     $destPath = $this->getUserFolder($ownerId);
     // first of all, check if the file is readable and if not, quit
     if (!File::isReadable($fileName)) {
         return false;
     }
     $destFile = $destPath . $destFile;
     if ($mode == RESOURCE_STORAGE_STORE_COPY) {
         $res = File::copy($fileName, $destFile);
     } else {
         $res = File::rename($fileName, $destFile);
     }
     if (!$res) {
         return false;
     }
     // check that the permissions are correct
     File::chMod($destFile, 0755);
     return $destFile;
 }