share.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. //$RUNTIME_NOAPPS = true;
  3. require_once('../../../lib/base.php');
  4. OC_JSON::checkAppEnabled('files_sharing');
  5. require_once('../lib_share.php');
  6. $userDirectory = "/".OC_User::getUser()."/files";
  7. $sources = explode(";", $_POST['sources']);
  8. $uid_shared_with = $_POST['uid_shared_with'];
  9. $permissions = $_POST['permissions'];
  10. foreach ($sources as $source) {
  11. // Make sure file exists and can be shared
  12. if ($source && OC_FILESYSTEM::file_exists($source) && OC_FILESYSTEM::is_readable($source)) {
  13. $source = $userDirectory.$source;
  14. // If the file doesn't exist, it may be shared with the current user
  15. } else if (!$source = OC_Share::getSource($userDirectory.$source)) {
  16. OC_Log::write('files_sharing',"Shared file doesn't exists :".$source,OC_Log::ERROR);
  17. echo "false";
  18. }
  19. try {
  20. $shared = new OC_Share($source, $uid_shared_with, $permissions);
  21. if ($uid_shared_with == OC_Share::PUBLICLINK) {
  22. echo $shared->getToken();
  23. }
  24. } catch (Exception $exception) {
  25. OC_Log::write('files_sharing',"Unexpected Error : ".$exception->getMessage(),OC_Log::ERROR);
  26. echo "false";
  27. }
  28. }
  29. ?>