original_string: public function uploadAction($parameter) {
          try {
              if(!$files = $this->request->files()) {
                  return $this->jsonResult(400, 'Failed to upload file.', 'error_upload_failed');
              }
  
              foreach($files as $file) {
                  if($error = $file->getError()) {
                      return $this->jsonResult(400, "Failed to upload file '%s'.", "error_upload_failed_detail", [$file->getError()]);
                  }
              }
  
              $this->initFromSession();
  
              $this->deleteFile();
  
              $dir = $this->getUploadDir();
  
              if(!Misc::recursiveMkdir($dir, 0700)) {
                  return $this->jsonResult(500, "Failed to create upload directory at '%s'.", "error_createdir_failed", [$dir]);
              }
  
              foreach($files as $file) {
                  $target = "$dir/".$file->getName();
  
                  if(!$file->moveTo($target)) {
                      return $this->jsonResult(500, 'Failed to move file.', 'error_move_failed');
                  }
              }
  
              $this->file = $target;
  
              $this->filename = $file->getName();
  
              $this->filesize = $file->getSize();
  
              $this->saveToSession();
  
              $this->cleanFiles();
  
              return $this->jsonResult();
          }
          catch(Exception $e) {
              return $this->jsonResult(500, $e->getMessage());
          }
      }
code: public function uploadAction($parameter) {
          try {
              if(!$files = $this->request->files()) {
                  return $this->jsonResult(400, 'Failed to upload file.', 'error_upload_failed');
              }
  
              foreach($files as $file) {
                  if($error = $file->getError()) {
                      return $this->jsonResult(400, "Failed to upload file '%s'.", "error_upload_failed_detail", [$file->getError()]);
                  }
              }
  
              $this->initFromSession();
  
              $this->deleteFile();
  
              $dir = $this->getUploadDir();
  
              if(!Misc::recursiveMkdir($dir, 0700)) {
                  return $this->jsonResult(500, "Failed to create upload directory at '%s'.", "error_createdir_failed", [$dir]);
              }
  
              foreach($files as $file) {
                  $target = "$dir/".$file->getName();
  
                  if(!$file->moveTo($target)) {
                      return $this->jsonResult(500, 'Failed to move file.', 'error_move_failed');
                  }
              }
  
              $this->file = $target;
  
              $this->filename = $file->getName();
  
              $this->filesize = $file->getSize();
  
              $this->saveToSession();
  
              $this->cleanFiles();
  
              return $this->jsonResult();
          }
          catch(Exception $e) {
              return $this->jsonResult(500, $e->getMessage());
          }
      }
code_tokens: public function uploadAction ( $ parameter ) { try { if ( ! $ files = $ this -> request -> files ( ) ) { return $ this -> jsonResult ( 400 , 'Failed to upload file.' , 'error_upload_failed' ) ; } foreach ( $ files as $ file ) { if ( $ error = $ file -> getError ( ) ) { return $ this -> jsonResult ( 400 , "Failed to upload file '%s'." , "error_upload_failed_detail" , [ $ file -> getError ( ) ] ) ; } } $ this -> initFromSession ( ) ; $ this -> deleteFile ( ) ; $ dir = $ this -> getUploadDir ( ) ; if ( ! Misc :: recursiveMkdir ( $ dir , 0700 ) ) { return $ this -> jsonResult ( 500 , "Failed to create upload directory at '%s'." , "error_createdir_failed" , [ $ dir ] ) ; } foreach ( $ files as $ file ) { $ target = "$dir/" . $ file -> getName ( ) ; if ( ! $ file -> moveTo ( $ target ) ) { return $ this -> jsonResult ( 500 , 'Failed to move file.' , 'error_move_failed' ) ; } } $ this -> file = $ target ; $ this -> filename = $ file -> getName ( ) ; $ this -> filesize = $ file -> getSize ( ) ; $ this -> saveToSession ( ) ; $ this -> cleanFiles ( ) ; return $ this -> jsonResult ( ) ; } catch ( Exception $ e ) { return $ this -> jsonResult ( 500 , $ e -> getMessage ( ) ) ; } }
docstring: Stores a received file. The request must be encoded as formdata.
  
  The first file in the formdata will be used, every other file is ignored.
  
  An json response will be generated and send back to the client.
  { 'success': TRUE|FALSE, [ 'error': errorstring ] }
docstring_tokens: Stores a received file . The request must be encoded as formdata .