/** * Move an uploaded file to the temporary directory and update file content. * * @param \BackBee\CoreDomain\ClassContent\AbstractClassContent $file * @param string $newfilename * @param string $originalname * * @return boolean|string * @throws \BackBee\ClassContent\Exception\ClassContentException Occures on invalid content type provided */ public function updateFile(AbstractClassContent $file, $newfilename, $originalname = null, $src = null) { if (false === $file instanceof ElementFile) { throw new ClassContentException('Invalid content type'); } if (null === $originalname) { $originalname = $file->originalname; } $base_dir = $this->_temporarydir; $file->originalname = $originalname; $file->path = Media::getPathFromContent($file); if (null === $file->getDraft()) { $base_dir = $this->isInMediaLibrary($file) ? $this->_mediadir : $this->_storagedir; } $moveto = $file->path; File::resolveFilepath($moveto, null, array('base_dir' => $base_dir)); try { if ($src === null) { File::resolveFilepath($newfilename, null, array('base_dir' => $this->_temporarydir)); File::move($newfilename, $moveto); } else { $dir = dirname($moveto); if (!is_dir($dir)) { File::mkdir($dir); } file_put_contents($moveto, base64_decode($src)); } $this->dispatchPostUploadEvent($moveto, $file->path); } catch (\BackBee\Exception\BBException $e) { return false; } return $moveto; }