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.

42 lines
1.5 KiB

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