Ejemplo n.º 1
0
 public function makeWritable()
 {
     $this->initConnection();
     // fetch current permissions on loaded file through FileSystemFile object
     try {
         $objFile = new \Cx\Lib\FileSystem\FileSystemFile($this->passedFilePath);
         $filePerms = $objFile->getFilePermissions();
         \DBG::msg('FTPFile: Fetched file permissions of ' . $this->passedFilePath . ': ' . substr(sprintf('%o', $filePerms), -4));
     } catch (FileSystemFileException $e) {
         throw new FTPFileException($e->getMessage());
     }
     // abort process in case the file is already writable
     // test: check write access for file owner
     if ($filePerms & \Cx\Lib\FileSystem\FileSystem::CHMOD_USER_WRITE) {
         return true;
     }
     // this is probably not required for FTP - TD / 11/1/2012
     /*$parentDirectory = dirname($this->passedFilePath);
       if (!is_writable($parentDirectory)) {
           if (strpos($parentDirectory, ASCMS_DOCUMENT_ROOT) === 0) {
               // parent directory lies within the Cloudrexx installation directory,
               // therefore, we shall try to make it writable
               \Cx\Lib\FileSystem\FileSystem::makeWritable($parentDirectory);
           } else {
               \DBG::msg('Parent directory '.$parentDirectory.' lies outside of Cloudrexx installation and can therefore not be made writable!');
           }
       }*/
     // set write access to file owner
     $filePerms |= \Cx\Lib\FileSystem\FileSystem::CHMOD_USER_WRITE;
     // log file permissions into the humand readable chmod() format
     \DBG::msg('FTPFile: CHMOD: ' . substr(sprintf('%o', $filePerms), -4));
     if (!ftp_chmod($this->connection, $filePerms, $this->filePath . '/' . $this->file)) {
         throw new FTPFileException('FTPFile: Unable to set write access to file ' . $this->filePath . '/' . $this->file . '!');
     }
 }