www-apps/phpSANE-0.8.0
[anomen-overlay.git] / www-apps / phpSANE / dev / download.php
blob1461d1625bc7f24a10c95e8d2a7f7f903bc63563
1 <?php
2 include("incl/functions.php");
3 include("incl/config.php");
5 if($do_file_download) {
6 //create zip file
7 $selected_file_paths = array();
8 foreach($_REQUEST['selected_files'] as $selected_file) {
9 $selected_file_path = $save_dir . basename($selected_file);
10 if(is_readable($selected_file_path)) {
11 array_push($selected_file_paths, $selected_file_path);
14 $zipfile_path = $temp_dir . 'scanned_' . time() . '.zip';
15 if(sizeof($selected_file_paths) > 0) {
16 create_zip($selected_file_paths, $zipfile_path, true);
17 if(is_readable($zipfile_path)) {
18 //output path to created file
19 echo $zipfile_path;
25 /* creates a compressed zip file */
26 function create_zip($files = array(),$destination = '',$overwrite = false) {
27 //if the zip file already exists and overwrite is false, return false
28 if(file_exists($destination) && !$overwrite) { return false; }
29 //vars
30 $valid_files = array();
31 //if files were passed in...
32 if(is_array($files)) {
33 //cycle through each file
34 foreach($files as $file) {
35 //make sure the file exists
36 if(file_exists($file)) {
37 $valid_files[] = $file;
41 //if we have good files...
42 if(count($valid_files)) {
43 //create the archive
44 $zip = new ZipArchive();
45 if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
46 return false;
49 //add the files
50 foreach($valid_files as $file) {
51 $zip->addFile($file, basename($file));
54 //close the zip
55 $zip->close();
57 //check to make sure the file exists
58 return file_exists($destination);
60 else
62 return false;