2017-09-19 7 views

答えて

2

をダウンロードするには、DCEは私見これは何もTYPO3の固有のものです。 「画像を表示するのではなく、ブラウザに画像をダウンロードさせる方法」

これを実現するには、画像の大きなバージョンへのリンクではなく、ブラウザに表示されます。

これは、DCEを適切に設定することで実現できます。

このPHPスクリプトは、イメージファイルをディスクから読み込み、クライアントがいくつかのHTTPヘッダーをtweekingする必要があります。

など。このようなもの。



    @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(); 

2

私たちのプロジェクトでは、別の方法を使用しました。画像にURLの接頭辞をつけました。 「バイナリ」とApacheの設定で適切なヘッダを定義した:

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

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

だから、アップロード/写真の画像を配置することができますし、バイナリ/アップロード/写真経由でそれらを取得する場合、ブラウザはそれらをダウンロードすることを余儀なくされます。元のURLも使用できます。

+0

これは非常に良い解決策です。私はそれを覚えておく必要があります。 –

関連する問題