Web Interface For Lite Argus Control modules
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.

52 lines
1.6 KiB

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