upload.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // Init owncloud
  3. require_once('../../lib/base.php');
  4. // Firefox and Konqueror tries to download application/json for me. --Arthur
  5. OC_JSON::setContentTypeHeader('text/plain');
  6. OC_JSON::checkLoggedIn();
  7. if (!isset($_FILES['files'])) {
  8. OC_JSON::error(array("data" => array( "message" => "No file was uploaded. Unknown error" )));
  9. exit();
  10. }
  11. foreach ($_FILES['files']['error'] as $error) {
  12. if ($error != 0) {
  13. $errors = array(
  14. 0=>$l->t("There is no error, the file uploaded with success"),
  15. 1=>$l->t("The uploaded file exceeds the upload_max_filesize directive in php.ini"),
  16. 2=>$l->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
  17. 3=>$l->t("The uploaded file was only partially uploaded"),
  18. 4=>$l->t("No file was uploaded"),
  19. 6=>$l->t("Missing a temporary folder")
  20. );
  21. OC_JSON::error(array("data" => array( "message" => $errors[$error] )));
  22. exit();
  23. }
  24. }
  25. $files=$_FILES['files'];
  26. $dir = $_POST['dir'];
  27. $dir .= '/';
  28. $error='';
  29. $totalSize=0;
  30. foreach($files['size'] as $size){
  31. $totalSize+=$size;
  32. }
  33. if($totalSize>OC_Filesystem::free_space('/')){
  34. OC_JSON::error(array("data" => array( "message" => "Not enough space available" )));
  35. exit();
  36. }
  37. $result=array();
  38. if(strpos($dir,'..') === false){
  39. $fileCount=count($files['name']);
  40. for($i=0;$i<$fileCount;$i++){
  41. $target=stripslashes($dir) . $files['name'][$i];
  42. if(OC_Filesystem::fromUploadedFile($files['tmp_name'][$i],$target)){
  43. $result[]=array( "status" => "success", 'mime'=>OC_Filesystem::getMimeType($target),'size'=>OC_Filesystem::filesize($target),'name'=>$files['name'][$i]);
  44. }
  45. }
  46. OC_JSON::encodedPrint($result);
  47. exit();
  48. }else{
  49. $error='invalid dir';
  50. }
  51. OC_JSON::error(array('data' => array('error' => $error, "file" => $fileName)));
  52. ?>