delete.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Björn Schießle <schiessle@owncloud.com>
  5. * @author Frank Karlitschek <frank@owncloud.org>
  6. * @author Jakob Sack <mail@jakobsack.de>
  7. * @author Joas Schilling <nickvergessen@owncloud.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Lukas Reschke <lukas@owncloud.com>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <icewind@owncloud.com>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Vincent Petry <pvince81@owncloud.com>
  14. *
  15. * @copyright Copyright (c) 2015, ownCloud, Inc.
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. OCP\JSON::checkLoggedIn();
  32. OCP\JSON::callCheck();
  33. \OC::$server->getSession()->close();
  34. // Get data
  35. $dir = isset($_POST['dir']) ? (string)$_POST['dir'] : '';
  36. $allFiles = isset($_POST["allfiles"]) ? (string)$_POST["allfiles"] : false;
  37. // delete all files in dir ?
  38. if ($allFiles === 'true') {
  39. $files = array();
  40. $fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
  41. foreach ($fileList as $fileInfo) {
  42. $files[] = $fileInfo['name'];
  43. }
  44. } else {
  45. $files = isset($_POST["file"]) ? (string)$_POST["file"] : (string)$_POST["files"];
  46. $files = json_decode($files);
  47. }
  48. $filesWithError = '';
  49. $success = true;
  50. //Now delete
  51. foreach ($files as $file) {
  52. if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) &&
  53. !(\OC\Files\Filesystem::isDeletable($dir . '/' . $file) &&
  54. \OC\Files\Filesystem::unlink($dir . '/' . $file))
  55. ) {
  56. $filesWithError .= $file . "\n";
  57. $success = false;
  58. }
  59. }
  60. // get array with updated storage stats (e.g. max file size) after upload
  61. try {
  62. $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
  63. } catch(\OCP\Files\NotFoundException $e) {
  64. OCP\JSON::error(['data' => ['message' => 'File not found']]);
  65. return;
  66. }
  67. if ($success) {
  68. OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
  69. } else {
  70. OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats)));
  71. }