delete.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. OCP\JSON::checkLoggedIn();
  3. OCP\JSON::callCheck();
  4. \OC::$session->close();
  5. // Get data
  6. $dir = stripslashes($_POST["dir"]);
  7. $allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : false;
  8. // delete all files in dir ?
  9. if ($allFiles === 'true') {
  10. $files = array();
  11. $fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
  12. foreach ($fileList as $fileInfo) {
  13. $files[] = $fileInfo['name'];
  14. }
  15. } else {
  16. $files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
  17. $files = json_decode($files);
  18. }
  19. $filesWithError = '';
  20. $success = true;
  21. //Now delete
  22. foreach ($files as $file) {
  23. if (($dir === '' && $file === 'Shared') || !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
  24. $filesWithError .= $file . "\n";
  25. $success = false;
  26. }
  27. }
  28. // get array with updated storage stats (e.g. max file size) after upload
  29. $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
  30. if ($success) {
  31. OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
  32. } else {
  33. OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats)));
  34. }