-
Notifications
You must be signed in to change notification settings - Fork 2
/
download.php
66 lines (60 loc) · 1.88 KB
/
download.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
include("incl/functions.php");
include("incl/config.php");
if($do_file_download) {
//create zip file
$selected_file_paths = array();
foreach($_REQUEST['selected_files'] as $selected_file) {
$selected_file_path = $save_dir . basename($selected_file);
if(is_readable($selected_file_path)) {
array_push($selected_file_paths, $selected_file_path);
}
}
$zipfile_path = $temp_dir . 'scanned_' . time() . '.zip';
if(sizeof($selected_file_paths) > 0) {
create_zip($selected_file_paths, $zipfile_path, true);
if(is_readable($zipfile_path)) {
//output path to created file
echo $zipfile_path;
}
}
}
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//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)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
$option = $overwrite && file_exists($destination) ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE;
if($zip->open($destination,$option) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file, basename($file));
}
//close the zip
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
?>