2013-10-25 2 views
1

다운로드 한 이미지의 zip 폴더를 만들려고합니다. 내 코드는 다음과 같습니다. 어떤 오류도 발생하지 않지만 zip이 다운로드되지 않습니다. 코드가 컴파일되고 현재 디렉토리의 표시 부분까지 출력을 얻고 있지만 코드가 어딘가에 잘못 표시되는 것처럼 보일 수 있습니다. 모든 Zip 아카이브를 얻으려면.PHP에서 zip 폴더 생성

<?php 
$conn_id=ftp_connect("localhost") or die("Could not connect"); 
ftp_login($conn_id,"kishan","ubuntu");  //login to ftp localhost 
echo "The current directory is " . ftp_pwd($conn_id); //display current directory 

ftp_chdir($conn_id,'/var/www/test1'); //changing to the directory where my images are downloaded. 
echo "<br/><p> Changing to directory" . ftp_pwd($conn_id); 
$file_folder="."; 

echo "<br/> The content of the directory is <br/>"; 
print_r(ftp_rawlist($conn_id,".")); // display the contents of the directory 

if(extension_loaded('zip'))  //check whether extension is loaded 
{ 
$zip=new ZipArchive(); 
$zip_name="a.zip";  //some name to my zip file 

if($zip->open($zip_name,ZIPARCHIVE::CREATE)!==TRUE) 
    { 
    $error="Sorry ZIP creation failed at this time"; 
    } 

$contents=ftp_nlist($conn_id,"."); 

foreach($contents as $file) //addition of files to zip one-by-one 
    { 
    $zip->addFile($file_folder.$file); 
    } 
$zip->close();  //seal the zip 
} 

if(file_exists($zip_name)) //Content-dispostion of my zip file 
{ 
header('Content-type:application/zip'); 
header('Content-Disposition:attachment; filename="'.$zip_name.'"'); 
readfile($zip_name); 
unlink($zip_name); 
} 

?> 

답변

0

for 루프에 전달 된 데이터에 이상이있는 것으로 나타났습니다.

$contents=ftp_nlist($conn_id,"."); 
foreach($contents as $file) //addition of files to zip one-by-one 
{ 
$zip->addFile($file_folder.$file); 
} 

정확히 어디에서 잘못 될지 모르지만 여기는 업데이트입니다. 내가 한 것은이 코드는 절대적으로 잘 작동

foreach($post['files'] as $file){    
$zip->addFile($file_folder.$file);} // Adding files into zip 

로, HTML을 사용하여 다음 POST 방법을 통해이 PHP 스크립트로 파일을 전달 쓰기 마크 업을했지만, 지금은 포스트 방법은 이유를 알아 내야 노력하고 내 파일을 압축하는 것은 정상적인 반면에 파일을 반복하지 않습니다 !!