У меня есть несколько файлов на моем веб-сайте, и я хочу, чтобы он мог загружать все эти файлы, архивируя их, а затем позволяя им загружать их.Я хочу выполнить архивирование на сервере, поэтому я искал несколько решений и нашел это Единственная проблема: это php-файл без html, и я просто не представляю, как реализовать вмоя веб-страница, поскольку у меня нулевой опыт работы с php.
Вот код моего сайта:
<?php include
'/home/www/***/***/***.php' ;
?>
<title>Downloads</title>
<style>
a:hover {
text-decoration: none;
}
</style>
<?php include
'/home/www/***/***/***.php' ;
?>
<div id="site" class="container">
<div class="row">
<div class="col-sm-12">
<h1><strong>Downloads</strong></h1>
<p>Welcome to this private page of mine, dedicated just for files too big to send via e-mail.<br>
Hope you are able to find what you need. If not, mail me: <a href="mailto:***@***?Subject=Question" target="_top">***@***</a>.</p>
</div>
</div>
<br>
<a href="files/***.txt" download="***.txt">
<div class="box downloadbox">
<div class="row">
<div class="col-sm-2 col-md-1 col-lg-2">
<img id="plaatjes" src="img/***/***/***.png" alt="-">
</div>
<div class="col-sm-10 col-md-11 col-lg-10">
<div class="series">
<br>
<br>
<h2><strong>Watch List</strong></h2>
</div>
</div>
</div>
</div>
</a>
<br>
</div>
<?php include
'/home/www/***/***/***.php' ;
?>
Вот код zip-файла php:
<code><?php
function zipFilesAndDownload($file_names,$archive_file_name,$file_path){
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
foreach($file_names as $files) {
$zip->addFile($file_path.$files,$files);
}
$zip->close();
$zipped_size = filesize($archive_file_name);
header("Content-Description: File Transfer");
header("Content-type: application/zip");
header("Content-Type: application/force-download");// some browsers need this
header("Content-Disposition: attachment; filename=$archive_file_name");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header("Content-Length:". " $zipped_size");
ob_clean();
flush();
readfile("$archive_file_name");
unlink("$archive_file_name"); // Now delete the temp file (some servers need this option)
exit;
}
if(isset($_POST['formSubmit'])) {
//$file_names=$_POST['items'];// Always sanitize your submitted data!!!!!!
//$file_names = filter_var_array($_POST['items']);//works but it's the wrong method
$filter = filter_input_array(INPUT_POST, FILTER_SANITIZE_SPECIAL_CHARS) ;
$file_names = $filter['items'] ;
//Archive name
$archive_file_name='DEMO-archive.zip';
//Download Files path
$file_path= getcwd(). '/content/';
//cal the function
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
} else {
header("Refresh: 5; url= ./index.php ");
print '<h1 style="text-align:center">You you shouldn\'t be here ......
перенаправление через 5 секунд ';
exit;
}
</code>
Я знаю, что это немного грязно, и, возможно, я не правильно задал вопрос, но я все еще надеюсь, что кто-то может мне помочь!