2014-09-13 2 views
-1

Zip 폴더 내의 이미지를 동적으로 보는 image.php 파일이 있습니다. 그래서 image.php? location =./folder/Hi.zip & file = image.jpg 이미지를 봅니다.php에서 zip 파일을 다운로드하도록 강요합니다.

다른 파일 downloadfile.php가있어 매개 변수에 지정된 파일을 다운로드해야합니다. downloadfile.php? 위치 = .folder/& 파일 = image.jpg를 *이 이미지를 다운로드 *

내가 필요로하는 downloadfile.php 사용 (image.php에 의해) 동적으로 생성 된 이미지를 다운로드하는 것입니다.

<?php 
header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
$file=$_GET['file'];$ext=$_GET['ext'];$location=$_GET['location']; 
header('Content-disposition: attachment; filename="'.$file.'"'); 
header('Content-type:"'.$ext.'"'); 
readfile("$location"."$file"); 
?> 

image.php

<?php 
function showimage($zip_file,$file_name) 
{ 
    $z=new ZipArchive(); 
    if($z->open($zip_file)!=true){ 
     echo "File not found"; 
     return false; 
    } 
    $stat=$z->statName($file_name); 

    $fp=$z->getStream($file_name); 
    if(!$fp){ 
     echo "Could not load image"; 
     return false; 
    } 
    header('Content-Type:image/'.$_GET['type']); 
    header('Content-Length:'. $stat['size']); 
    fpassthru($fp); 
    return true; 
} 
showimage($_GET['zip'],$_GET['file']); 
?> 

어떤 제안이 downloadfile.php

? 당신이 image.php 에서 코드를 사용하고 단지

header("Content-Transfer-Encoding: binary"); 
header('Content-Description: File Transfer'); 
header('Content-Type:image/'.$_GET['type']); 
header('Content-Length: ' . $stat['size']); 
header('Content-Disposition: attachment; filename=' . $file_name); 

이 사용자를 강제로

header('Content-Type:image/'.$_GET['type']); 
header('Content-Length:'. $stat['size']); 

에서 헤더 를 변경할 수있는 이미지 파일을 다운로드 브라우저를 강제하기 위해

답변

2

이미지를 표시하는 대신 다운로드하십시오.

관련 문제