Пример #1
0
 /**
  * Download a resource file content
  * @param {String} uri Uri of the resource file
  */
 public function downloadFile()
 {
     if ($this->hasRequestParameter('uri')) {
         $uri = tao_helpers_Uri::decode($this->getRequestParameter('uri'));
         $resource = new core_kernel_classes_Resource($uri);
         if (core_kernel_versioning_File::isVersionedFile($resource) || core_kernel_file_File::isFile($resource)) {
             $file = new core_kernel_file_File($uri);
             $fileName = $file->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FILE_FILENAME));
             $content = $file->getFileContent();
             $size = strlen($content);
             $mimeType = tao_helpers_File::getMimeType($file->getAbsolutePath(), true);
             $this->setContentHeader($mimeType);
             header("Content-Length: {$size}");
             header("Content-Disposition: attachment; filename=\"{$fileName}\"");
             header("Expires: 0");
             header("Cache-Control: no-cache, must-revalidate");
             header("Pragma: no-cache");
             print $content;
             return;
         } else {
             throw new Exception('The resource (' . $uri . ') is not a valid file resource');
         }
     }
 }