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);
}
?>