2017-09-19 1 views

답변

2

이럴 일부 엄지 손가락을 표시하고 다운로드합니다. 실제 질문 : "브라우저가 이미지를 표시하는 대신 이미지를 다운로드하도록하는 방법"

이렇게하려면 푸시 할 이미지의 식별자를 전달하는 PHP 스크립트에 해당 축소판을 링크해야합니다 브라우저 대신 이미지의 큰 버전에 대한 링크로 이동하십시오.

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에 이미지 앞에 접두어를 붙였습니다. "진"과 아파치 구성에서 해당 헤더 정의 :

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

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

그래서 당신이 업로드/사진의 이미지를 배치 할 수 있습니다 당신은 바이너리/업로드/사진을 통해 그들을 검색 할 경우 브라우저를 다운로드하도록 강요됩니다. 원본 URL도 사용할 수 있습니다.

+0

이것은 가능한 아주 좋은 해결책입니다. 나는 그것을 명심해야한다. –

관련 문제