Commit 0a31e92d authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

default option set to download single zip

parent 49717aca
...@@ -111,7 +111,7 @@ function respond_xml($result,$error=null,$color_mode = 3){ // default white bold ...@@ -111,7 +111,7 @@ function respond_xml($result,$error=null,$color_mode = 3){ // default white bold
header("Pragma: no-cache\n"); header("Pragma: no-cache\n");
printf($rslt); printf($rslt);
} }
if (isset($GLOBALS['logFile'])){ if (isset($GLOBALS['logFile'])){
if ($result !== ""){ //"" will not be loged/output if ($result !== ""){ //"" will not be loged/output
log_msg(''.$result,$color_mode); log_msg(''.$result,$color_mode);
...@@ -128,7 +128,7 @@ function respond_xml($result,$error=null,$color_mode = 3){ // default white bold ...@@ -128,7 +128,7 @@ function respond_xml($result,$error=null,$color_mode = 3){ // default white bold
// PARALLEL HTTP REQUESTS // PARALLEL HTTP REQUESTS
// Using parallel requests, PHP has to be configured '--with-curl=' (and libcurl should be installed) // Using parallel requests, PHP has to be configured '--with-curl=' (and libcurl should be installed)
function curl_multi_start($urls) { function curl_multi_start($urls, $with_headers=0) {
// numprime is needed to actually send the request and remote starts executing it // numprime is needed to actually send the request and remote starts executing it
// Not really clear - what it should be // Not really clear - what it should be
$numprime = 4; // magic number, see http://lampe2e.blogspot.com/2015/03/making-stuff-faster-with-curlmultiexec.html $numprime = 4; // magic number, see http://lampe2e.blogspot.com/2015/03/making-stuff-faster-with-curlmultiexec.html
...@@ -138,7 +138,7 @@ function curl_multi_start($urls) { ...@@ -138,7 +138,7 @@ function curl_multi_start($urls) {
$ch = curl_init (); $ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_HEADER, $with_headers);
$aCurlHandles[] = $ch; $aCurlHandles[] = $ch;
curl_multi_add_handle ($curl_mh, $ch); curl_multi_add_handle ($curl_mh, $ch);
} }
...@@ -151,8 +151,8 @@ function curl_multi_start($urls) { ...@@ -151,8 +151,8 @@ function curl_multi_start($urls) {
} }
return array ("mh" => $curl_mh,"handles" => $aCurlHandles); return array ("mh" => $curl_mh,"handles" => $aCurlHandles);
} }
function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false) { function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false, $with_headers = 0) {
$curl_active = 1; $curl_active = 1;
$curl_mrc = CURLM_OK; $curl_mrc = CURLM_OK;
$nrep = 0; $nrep = 0;
...@@ -170,6 +170,7 @@ function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false) { ...@@ -170,6 +170,7 @@ function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false) {
} }
} }
$results = array (); $results = array ();
$names = array ();
if ($use_xml) { if ($use_xml) {
foreach ($data['handles'] as $i => $ch) { foreach ($data['handles'] as $i => $ch) {
$xml = simplexml_load_string (curl_multi_getcontent ($ch)); $xml = simplexml_load_string (curl_multi_getcontent ($ch));
...@@ -187,13 +188,50 @@ function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false) { ...@@ -187,13 +188,50 @@ function curl_multi_finish($data, $use_xml=true, $ntry=0, $echo = false) {
foreach ($data['handles'] as $i => $ch) { foreach ($data['handles'] as $i => $ch) {
$r = curl_multi_getcontent ($ch); $r = curl_multi_getcontent ($ch);
curl_multi_remove_handle ($curl_mh, $ch); curl_multi_remove_handle ($curl_mh, $ch);
if ($with_headers==1){
$hsize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$h = substr($r, 0, $hsize);
$r = substr($r, $hsize);
$names[] = curl_get_filename_from_header($h);
}
$results[] = $r; $results[] = $r;
} }
if ($with_headers==1){
$results = Array('names' => $names,'contents'=> $results);
}
} }
curl_multi_close ($curl_mh); curl_multi_close ($curl_mh);
return $results; return $results;
} }
function curl_get_filename_from_header($h){
$h = explode("\n",$h);
$res = "";
if ($h){
foreach($h as $e){
if (strlen($e)!=0){
$tmp = explode(":",$e);
if ($tmp[0]=="Content-Disposition"){
$tmp = explode(";",$tmp[1]);
foreach($tmp as $t){
$t = trim($t);
$t = explode("=",$t);
if ($t[0]=="filename"){
$res = trim($t[1]," \t\n\r\0\x0B\"");
break;
}
}
break;
}
}
}
}
return $res;
}
// DEVICES // DEVICES
/** Get a list of suitable partitions. The list will contain SATA devices only and /** Get a list of suitable partitions. The list will contain SATA devices only and
...@@ -218,7 +256,7 @@ function get_partitions() ...@@ -218,7 +256,7 @@ function get_partitions()
/** Get a list of disk devices which have file system and can be mounted. This function /** Get a list of disk devices which have file system and can be mounted. This function
* uses 'blkid' command from busybox. * uses 'blkid' command from busybox.
*/ */
function get_mnt_dev() function get_mnt_dev()
{ {
$partitions = get_partitions(); $partitions = get_partitions();
...@@ -237,7 +275,7 @@ function get_mnt_dev() ...@@ -237,7 +275,7 @@ function get_mnt_dev()
$i++; $i++;
} }
} }
return array("devices" => $devices, "types" => $fs_types); return array("devices" => $devices, "types" => $fs_types);
} }
...@@ -246,12 +284,12 @@ function get_raw_dev() ...@@ -246,12 +284,12 @@ function get_raw_dev()
{ {
$j = 0; $j = 0;
$ret = get_mnt_dev(); $ret = get_mnt_dev();
$devices = $ret["devices"]; $devices = $ret["devices"];
$types = $ret["types"]; $types = $ret["types"];
$names = get_partitions(); $names = get_partitions();
// filter out partitions with file system // filter out partitions with file system
$i = 0; $i = 0;
$raw_devices = array(); $raw_devices = array();
...@@ -267,7 +305,7 @@ function get_raw_dev() ...@@ -267,7 +305,7 @@ function get_raw_dev()
$i++; $i++;
} }
} }
//special case //special case
if (count($raw_devices)>1) { if (count($raw_devices)>1) {
foreach($raw_devices as $k=>$v){ foreach($raw_devices as $k=>$v){
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
?> ?>
<?php <?php
include "../include/elphel_functions_include.php";
$port0 = 2323; $port0 = 2323;
$path = "/sys/devices/soc0/elphel393-detect_sensors@0"; $path = "/sys/devices/soc0/elphel393-detect_sensors@0";
$available_ports = Array(); $available_ports = Array();
...@@ -99,49 +101,54 @@ ...@@ -99,49 +101,54 @@
if (isset($_GET['zip'])){ if (isset($_GET['zip'])){
$tmpdir = "/tmp/snapshot"; $contents = Array();
$filenames = Array();
// create tmp dir $rqs = Array();
if (!is_dir($tmpdir)){ foreach($available_ports as $port){
mkdir($tmpdir); array_push($rqs,"http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg");
} }
$cdata = curl_multi_start($rqs,1);
$results = curl_multi_finish($cdata,false,0,false,1);
$filenames = $results['names'];
$contents = $results['contents'];
/*
foreach($available_ports as $port){ foreach($available_ports as $port){
exec("wget --content-disposition -P $tmpdir http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg"); //exec("wget --content-disposition -P $tmpdir http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg");
//fopen("http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg",'r');
$content = file_get_contents("http://{$_SERVER['SERVER_ADDR']}:$port/timestamp_name/bimg");
$filename = get_filename_from_headers($http_response_header);
if ($filename==""){
$filename = "bimg.jp4";
}
array_push($filenames,$filename);
array_push($contents,$content);
} }
*/
$fstring = ""; $zipfilename = preg_replace("/_\d+\.jp4$/",".zip",$filenames[0]);
$zipfile = "bimg.zip";
$files = scandir($tmpdir); //tmpfile
//remove . & .. $tmpfile = tmpfile();
array_splice($files,0,2); $tmpfilename = stream_get_meta_data($tmpfile)['uri'];
$prefixed_files = preg_filter('/^/', "$tmpdir/", $files); $zip = new ZipArchive;
$fstring = implode(" ",$prefixed_files);
// pick name for the zip archive if ($zip->open($tmpfilename, ZipArchive::OVERWRITE)!==TRUE) {
foreach($files as $file){ die("cannot access temporary file <$tmpfilename>\n");
$tmp = explode(".",$file);
if ($tmp[1]=="jp4"||$tmp[1]=="jpeg"){
$tmp = explode("_",$tmp[0]);
if ($tmp[2]=="0"){
$zipfile = $tmp[0]."_".$tmp[1].".zip";
break;
}
}
} }
$zipped_data = `zip -qj - $fstring `; foreach($filenames as $k=>$v){
header('Content-type: application/zip'); $zip->addFromString($v,$contents[$k]);
header('Content-Disposition: attachment; filename="'.$zipfile.'"');
echo $zipped_data;
// clean up
foreach($prefixed_files as $file){
unlink($file);
} }
$zip->close();
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zipfilename.'"');
echo file_get_contents($tmpfilename);
die(); die();
} }
......
...@@ -59,6 +59,8 @@ function download_all(rtp){ ...@@ -59,6 +59,8 @@ function download_all(rtp){
pass_to_file_reader(filename,http.response); pass_to_file_reader(filename,http.response);
if ($("#synced").prop("checked")) { if ($("#synced").prop("checked")) {
read_tp(); read_tp();
}else{
$("#snapshot").attr("disabled",false);
} }
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment