-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportAllresults.php
86 lines (76 loc) · 2.5 KB
/
exportAllresults.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
session_start();
require_once('FirePHPCore/FirePHP.class.php');
$firephp = FirePHP::getInstance(true);
//$firephp->log(session_id(), 'session_id');
function create_zip($files = array(), $destination = './', $overwrite = true) {
$firephp = FirePHP::getInstance(true);
//$firephp->log($files, '$files');
//$firephp->log($destination, '$destination');
//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)) {
//$firephp->log($valid_files, '$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) {
$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();
//$firephp->log($zip, '$zip');
//check to make sure the file exists
return file_exists($destination);
} else {
return false;
}
}
if (!empty($_GET['jsonString'])) {
$params1 = $_GET["jsonString"];
}
$params1 = preg_replace('/"/', '\"', $params1);
/* creates a compressed zip file */
$session_id = session_id();
$path = getcwd() . DIRECTORY_SEPARATOR . $session_id;
chdir($path);
$files = scandir('.');
$destination = 'myzipfile.zip';
$status = create_zip($files,$destination, true);
$ret = array('status' => 'failed');
if ($status == false) {
// Command execution failed
// echo "Error running R";
$ret = json_encode( $ret );
} else {
// Command executed OK.
// echo "OK!";
$folder = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], "/") + 1);
$host = $_SERVER['HTTP_HOST'];
$fileURL = "http://" . $host . $folder . '/' . session_id() . '/' . $destination;
$ret ['status'] = 'ok';
$ret ['fileURL'] = $fileURL;
$ret = json_encode($ret);
}
echo isset($_GET['callback']) ? "{$_GET['callback']}($ret)" : $ret;
?>