/**
  * Gets the contents of the attachment given by it's database identifier from the filesystem 
  * 
  * @param $id integer the database identifier of the attachment
  * @return string the contents of the attachment or null on error
  */
 protected function getAttachmentContentFromFS($id)
 {
     $query = "SELECT file_size,compression_type,file_path " . " FROM {$this->tables['attachments']} WHERE id = {$id}";
     $row = $this->db->fetchFirstRow($query);
     $content = null;
     if ($row) {
         $filePath = $row['file_path'];
         $fileSize = $row['file_size'];
         $destFPath = $this->repositoryPath . DIRECTORY_SEPARATOR . $filePath;
         switch ($row['compression_type']) {
             case TL_REPOSITORY_COMPRESSIONTYPE_NONE:
                 $content = getFileContents($destFPath);
                 break;
             case TL_REPOSITORY_COMPRESSIONTYPE_GZIP:
                 $content = gzip_readFileContent($destFPath, $fileSize);
                 break;
         }
     }
     return $content;
 }
Ejemplo n.º 2
0
/**
 * uncompresses arbitrary gzipped content
 *
 * @param string content the compressed content
 * @param int $fileSize the original size of the uncompressed content
 *
 * @return string returns the uncompressed contents on success or null on error
 */
function gzip_uncompress_content($content, $fileSize)
{
    global $g_repositoryPath;
    $dest = $g_repositoryPath . DIRECTORY_SEPARATOR . session_id() . ".dummy.gz";
    $fp = fopen($dest, "wb");
    if ($fp) {
        fwrite($fp, $content, strlen($content));
        fclose($fp);
        return gzip_readFileContent($dest, $fileSize);
    }
    return null;
}