詳細を教えていただければ、次のコードがリンクに役立つと思います。
<?php
$files = scandir('../snaps');
foreach($files as $file){ ?>
<a href="../<?php echo $file; ?>"><?php echo $file; ?></a>
<?
}
?>
Zipファイルを作成する機能です
<?
function create_zip($files = array(),$destination = '',$overwrite = false, $distill_subdirectories = true) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
// echo 1;
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
if ($distill_subdirectories) {
$zip->addFile($file, basename($file) );
} else {
$zip->addFile($file, $file);
}
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
//return file_exists($destination);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename={$destination}");
ob_clean();
flush();
readfile($destination);
//echo $destination;
}
else
{
return false;
}
}
?>
そして、これはあなたがそれを呼び出すことができる方法です:
$files = scandir('../snaps');
$to_zip = array();
foreach($files as $file){
if($file != "." AND $file !=".."){
$to_zip[] = $folder . "/".$file;
}
}
$zip = create_zip($to_zip, "test.zip", true);