コード例 #1
0
 /**
  * If folder is not present create it and then copy the file
  *
  * @param string $oldImagePath The source file path
  * @param string $newImagePath The target file path
  *
  * @return void
  *
  * @throws \InvalidArgumentException
  * @throws ApplicationException
  */
 protected function createDirAndCopyFile($oldImagePath, $newImagePath)
 {
     try {
         if (!is_dir(dirname($newImagePath))) {
             File::mkdir(dirname($newImagePath));
         }
         File::copy($oldImagePath, $newImagePath);
     } catch (InvalidArgumentException $e) {
         throw new \InvalidArgumentException($e->getMessage());
     } catch (ApplicationException $e) {
         throw $e;
     }
 }
コード例 #2
0
ファイル: FileTest.php プロジェクト: nextinteractive/utils
 /**
  * @expectedException \BackBee\Utils\Exception\InvalidArgumentException
  */
 public function testUnknownDirMkdir()
 {
     File::mkdir('');
     File::mkdir(null);
 }
コード例 #3
0
 /**
  * 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;
 }