-
Notifications
You must be signed in to change notification settings - Fork 0
/
zip_and_download_archive_dir.php
44 lines (43 loc) · 1.57 KB
/
zip_and_download_archive_dir.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/* Download all results. Copy everything to to_archive directory, zip
* that, then download. Afterwards, delete resulting zip file and all
* to_archive and empty subdirectories.
*/
require('functions.php');
$form_action = 'download_results.php';
$submit_text = 'Download';
$form_head = '';
$form_text = 'Enter password to download current results.';
if (!isset($_GET['pass'])) {
// Missing password
require('header.php');
require('password_form.php');
require('footer.php');
} elseif (!password_verify($_GET['pass'], $password_hash)) {
// Wrong password
$form_head = 'Password incorrect';
$form_text = 'Enter password to download current results';
$submit_text = 'Download';
require('header.php');
require('password_form.php');
require('footer.php');
} else {
$dt = new DateTime('NOW');
$now = $dt->format('Y-m-d');
$archive_filename = "project-inclusive_results_$now.tar.gz";
$archive_file = "$results_directory/$archive_filename";
exec("tar -zcvf $archive_file $results_directory/zipped");
header_remove();
header('Content-Description: File Transfer');
header('Content-Type: application/gzip');
header('Content-Disposition: attachment; filename="' . "$archive_filename" . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($archive_file));
flush();
readfile($archive_file);
unlink($archive_file);
}
?>