是否有可能在TYPO3中下载图像而不是显示它

时间:2017-09-19 11:29:28

标签: image typo3

TYPO3是否有可能下载照片而不是在浏览器中显示照片? 属性下载仅适用于非常新的浏览器,但不适用于IE11 ...

我只想用f.e. dce显示一些拇指并下载完整的照片

由于 沃尔克

2 个答案:

答案 0 :(得分:2)

恕我直言,这不是TYPO3的具体内容。 真正的问题是:“如何让浏览器下载图像而不是显示它”

要实现这一点,您需要将该缩略图链接到PHP脚本,将您想要推送到浏览器的图像的某种标识符传递给浏览器,而不是链接到图像的大版本。

您可以通过适当地配置DCE来实现此目的。

然后,这个PHP脚本需要从磁盘读取映像文件并将其推送到客户端,从而调出一些HTTP头。

E.g。像这样的东西。



    @ob_end_clean(); //turn off output buffering to decrease cpu usage

    $filePath = '/some/path/to/an_image.jpg';

    // deliver the file
    if (is_file($filePath))
    {
      // required for IE, otherwise Content-Disposition may be ignored
     if(ini_get('zlib.output_compression'))
        ini_set('zlib.output_compression', 'Off');

     header('Content-Type: application/force-download');
     header('Content-Disposition: attachment; filename="' . basename($filePath) . '"');
     header("Content-Transfer-Encoding: binary");
     header('Accept-Ranges: bytes');
     header("Cache-control: no-cache, pre-check=0, post-check=0");
     header("Cache-control: private");
     header('Pragma: private');
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

     $size = filesize($filePath);
     header("Content-Length: ".$size);

     // pass the file to the client
     readfile($filePath);

  } else die('Error - can not open file.');

  die(); 

答案 1 :(得分:2)

我们在其中一个项目中采用了不同的方法。我们用例如URL将URL加到图像上。 “binary”并在apache配置中定义了相应的头:

Alias /binary "PATH/TO/WEBROOT/uploads/pics" 

<Location /binary>
    ForceType application/octet-stream
    Header set Content-Disposition attachment
</Location>

因此,您可以将图像放在上传/图片中,如果您通过二进制/上传/图片检索它们,浏览器将被迫下载它们。您也可以使用原始网址。