Web UI for ARGUS server
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.

53 lines
1.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once( '/srv/etc/sys_map.php' );
  3. require_once( 'toolkit.php' );
  4. // the response function
  5. function verbose( $ok=1,$info=""){
  6. // failure to upload throws 400 error
  7. if( $ok==0 ){
  8. http_response_code(400);
  9. };
  10. die(json_encode(["ok"=>$ok, "info"=>$info]));
  11. };
  12. // invalid upload
  13. if( empty( $_FILES ) || $_FILES['file']['error'] ){
  14. verbose( 0, "Failed to move uploaded file.[" . $_FILES['file']['error'] . "]" );
  15. };
  16. // upload destination
  17. //$filePath = __DIR__ . DIRECTORY_SEPARATOR . "../../vault/working_dir/uploads";
  18. $filePath = $GTEMP_DIR . '/uploads';
  19. if( !file_exists($filePath) ){
  20. if (!mkdir($filePath, 0777, true)) {
  21. verbose(0, "Failed to create $filePath");
  22. };
  23. };
  24. $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : $_FILES["file"]["name"];
  25. $filePath = $filePath . DIRECTORY_SEPARATOR . $fileName;
  26. // dealing with the chunks
  27. $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
  28. $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
  29. $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
  30. if( $out ) {
  31. $in = @fopen($_FILES['file']['tmp_name'], "rb");
  32. if( $in ){
  33. while( $buff = fread( $in, 4096 ) ){
  34. fwrite($out, $buff);
  35. };
  36. } else {
  37. verbose(0, "Failed to open input stream");
  38. };
  39. @fclose($in);
  40. @fclose($out);
  41. @unlink($_FILES['file']['tmp_name']);
  42. } else {
  43. verbose(0, "Failed to open output stream");
  44. };
  45. // check if file was uploaded
  46. if (!$chunks || $chunk == $chunks - 1) {
  47. rename("{$filePath}.part", $filePath);
  48. if( createNewTask( 3, $fileName, 'Handle Upload File' ) == 0 ){
  49. unlink( $filePath );
  50. verbose(0, "Failed to create new Task");
  51. };
  52. };
  53. verbose(1, "Upload OK");
  54. ?>