/** * @param array $source * @param PropertyMappingConfigurationInterface $configuration * @return Resource|Error * @throws Exception */ protected function handleFileUploads(array $source, PropertyMappingConfigurationInterface $configuration = null) { if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) { if (isset($source['originallySubmittedResource']) && isset($source['originallySubmittedResource']['__identity'])) { return $this->persistenceManager->getObjectByIdentifier($source['originallySubmittedResource']['__identity'], \TYPO3\Flow\Resource\Resource::class); } return null; } if ($source['error'] !== \UPLOAD_ERR_OK) { switch ($source['error']) { case \UPLOAD_ERR_INI_SIZE: case \UPLOAD_ERR_FORM_SIZE: case \UPLOAD_ERR_PARTIAL: return new Error(Files::getUploadErrorMessage($source['error']), 1264440823); default: $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', Files::getUploadErrorMessage($source['error'])), LOG_ERR); return new Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849); } } if (isset($this->convertedResources[$source['tmp_name']])) { return $this->convertedResources[$source['tmp_name']]; } $resource = $this->resourceManager->importUploadedResource($source, $this->getCollectionName($source, $configuration)); if ($resource === false) { return new Error('The Resource Manager could not create a Resource instance for an uploaded file. See log for more details.', 1264517906); } else { $this->convertedResources[$source['tmp_name']] = $resource; return $resource; } }
/** * action for html5 multifile upload * * @param Folder $folder */ public function multiUploadAction(Folder $folder) { if (isset($_FILES) && !empty($_FILES)) { $count = 0; foreach ($_FILES as $file) { foreach ($file['name'] as $filename) { if ($file['name'][$count] != "") { $resource = array('tmp_name' => $file['tmp_name'][$count], 'name' => $file['name'][$count]); /** @var \TYPO3\Flow\Resource\Resource $newResource */ $newResource = $this->resourceManager->importUploadedResource($resource); $newFile = new File(); $newFile->setParentFolder($folder); $newFile->setOriginalResource($newResource); $newFile->setName($newResource->getFilename()); $this->fileRepository->add($newFile); $count++; } } } } $this->redirect('index', 'Folder', NULL, array('folder' => $folder)); }
/** * @param array $source * @return Resource|Error|NULL */ protected function handleFileUploads(array $source) { if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) { if (isset($source['submittedFile']) && isset($source['submittedFile']['filename']) && isset($source['submittedFile']['resourcePointer'])) { $resourcePointer = $this->persistenceManager->getObjectByIdentifier($source['submittedFile']['resourcePointer'], 'TYPO3\\Flow\\Resource\\ResourcePointer'); if ($resourcePointer) { $resource = new Resource(); $resource->setFilename($source['submittedFile']['filename']); $resource->setResourcePointer($resourcePointer); return $resource; } } return NULL; } if ($source['error'] !== \UPLOAD_ERR_OK) { switch ($source['error']) { case \UPLOAD_ERR_INI_SIZE: case \UPLOAD_ERR_FORM_SIZE: case \UPLOAD_ERR_PARTIAL: return new Error(Files::getUploadErrorMessage($source['error']), 1264440823); default: $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', Files::getUploadErrorMessage($source['error'])), LOG_ERR); return new Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849); } } if (isset($this->convertedResources[$source['tmp_name']])) { return $this->convertedResources[$source['tmp_name']]; } $resource = $this->resourceManager->importUploadedResource($source); if ($resource === FALSE) { return new Error('The resource manager could not create a Resource instance.', 1264517906); } else { $this->convertedResources[$source['tmp_name']] = $resource; return $resource; } }
public function addAction() { $currentUser = $this->authenticationManager->getSecurityContext()->getAccount()->getParty(); $photoInfo = $this->request->getArgument("photo"); $actionData = $this->request->getArgument("action"); $actionData = json_decode($actionData, true); $animalData = $this->request->getArgument("animal"); $animalData = json_decode($animalData, true); $ownerData = $this->request->getArgument("owner"); $ownerData = json_decode($ownerData, true); $photoData = $this->request->getArgument("photo"); $action = $this->propertyMapper->convert($actionData, 'DLigo\\Animaltool\\Domain\\Model\\Action'); $action->setDate(new \DateTime('now')); $user = $this->propertyMapper->convert($actionData['team'], 'DLigo\\Animaltool\\Domain\\Model\\User'); $lastId = $user->getLastBoxID(); $action->setTeam($user); $box = explode('-', $actionData['boxID']); if ($lastId > $box[1]) { $action->setBoxID($user->getTeamID() . '-' . ($lastId + 1)); } $animal = $this->propertyMapper->convert($animalData, 'DLigo\\Animaltool\\Domain\\Model\\Animal'); $birthday = \DateTime::createFromFormat("U", $animalData["birthday"]); if (!empty($animalData["birthday"])) { $birthday = \DateTime::createFromFormat("U", $animalData["birthday"]); $birthday->setTime(0, 0, 0); $animal->setBirthday($birthday); } $action->setAnimal($animal); $owner = null; if (isset($animalData["isPrivate"]) && $animalData["isPrivate"]) { $owner = $this->propertyMapper->convert($ownerData, 'DLigo\\Animaltool\\Domain\\Model\\Owner'); $animal->setOwner($owner); $animal->setEarTag(null); if (!empty($animalData["earTag"])) { $rfid = $animalData["earTag"]; $oldAnimal = $this->animalRepository->findOneByRFID($rfid); if ($oldAnimal == null) { $animal->setRFID($rfid); } } } else { if (!empty($animalData["earTag"])) { $eartag = $animalData["earTag"]; $oldAnimal = $this->animalRepository->findOneByEarTag($eartag); if ($oldAnimal != null) { $animal->setEarTag(null); } } } $photo = $this->resourceManager->importUploadedResource($photoInfo); //$this->systemLogger->log(\TYPO3\Flow\var_dump($photo,"Photo",true,true),LOG_INFO); $animal->setPhoto($photo); if ($owner) { $this->ownerRepository->add($owner); } $this->animalRepository->add($animal); $this->actionRepository->add($action); $this->userRepository->update($user); $this->persistenceManager->persistAll(); $this->response->setStatus(201); echo "{" . '"lastID": ' . $currentUser->getLastBoxID() . "}"; flush(); ob_flush(); }