You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
2.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. require_once('../php/argus/server.php');
  4. $UID = intval( $CUser->Data['id'] );
  5. $ACCESS = intval( $CUser->Data['access'] );
  6. if( $CUser->Data['id'] > 1 ){
  7. if( isset( $_GET['SESSION'] ) ) $SESID = intval( $_GET['SESSION'] ); else $SESID = 0;
  8. if( isset( $_GET['VID'] ) ) $VID = intval( $_GET['VID'] ); else $VID = 0;
  9. if( $SESID ){
  10. $QS = "SELECT * FROM `sessions` WHERE `id`={$SESID}";
  11. $RR = $DATABASE->Query( $QS );
  12. if( count( $RR ) ){
  13. $SD = $RR[0];
  14. $Data['basepath'] = '/lib/controller/data/reports/'.$SD['track_id'].'/'.date("Y/m/d",intval( $SD['ts'] ));
  15. if( file_exists( $SYSPath . $Data['basepath'] )){
  16. $DBN = $SYSPath . $Data['basepath'] .'/report.db';
  17. //echo $DBN;
  18. //if( !file_exists( $DBN )) echo "Not Exist!!";
  19. $RBASE = new SQLite_DB( $DBN );
  20. $QS = "SELECT * FROM `videos` WHERE `session_id`={$SESID} AND `id`={$VID}";
  21. $RR = $RBASE->Query( $QS );
  22. $CR = $RR[0];
  23. $NAME = $CR['uuid'] . '.'. $CR['ext'];
  24. $filePath = $SYSPath . $Data['basepath'] . '/' . $NAME;
  25. if( file_exists($filePath) ){
  26. $QS = "SELECT `ms`.`short`, `mp`.`level`, `mt`.`short` as `tshort` FROM ( `metro_tracks` `mt` LEFT JOIN `metro_platforms` `mp` ON ( `mt`.`platform_id`=`mp`.`id`) ) LEFT JOIN `metro_stations` `ms` ON ( `mp`.`station_id` = `ms`.`id` ) WHERE `mt`.`id`={$SD['track_id']}";
  27. $RR = $DATABASE->Query( $QS );
  28. $downloadName = $RR[0]['short'].'_'.$RR[0]['level'].'_'.$RR[0]['tshort'].'_'.date("Y-m-d_H.i.s", $CR['ts'] ).'.'. $CR['ext'];
  29. // 1. Clear any previous output buffers
  30. if (ob_get_level()) {
  31. ob_end_clean();
  32. }
  33. // 2. Set the content type (e.g., application/pdf, image/jpeg, or application/octet-stream)
  34. header('Content-Type: application/octet-stream');
  35. // 3. Force download and define the file name
  36. header('Content-Disposition: attachment; filename="' . $downloadName. '"');
  37. // 4. Provide the exact file size to show download progress
  38. header('Content-Length: ' . filesize($filePath));
  39. // 5. Read the file and write it directly to the output buffer
  40. readfile($filePath);
  41. exit;
  42. } else {
  43. die("Error: The requested file does not exist.");
  44. };
  45. };
  46. };
  47. };
  48. };
  49. ?>