當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::getPath方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\File::getPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getPath方法的具體用法?PHP File::getPath怎麽用?PHP File::getPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\File\File的用法示例。


在下文中一共展示了File::getPath方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testGetDefaultExtensionIsBasedOnMimeType

 public function testGetDefaultExtensionIsBasedOnMimeType()
 {
     $file = new File(__DIR__ . '/Fixtures/test');
     $guesser = $this->createMockGuesser($file->getPath(), 'image/gif');
     MimeTypeGuesser::getInstance()->register($guesser);
     $this->assertEquals('.gif', $file->getDefaultExtension());
 }
開發者ID:netixpro,項目名稱:symfony,代碼行數:7,代碼來源:FileTest.php

示例2: transform

 /**
  * Transforms a File instance to a path
  *
  * @param File $file The file
  *
  * @return string The path to the file
  *
  * @throws UnexpectedTypeException if the given file is not an instance of File
  */
 public function transform($file)
 {
     if (null === $file || '' === $file) {
         return '';
     }
     if (!$file instanceof File) {
         throw new UnexpectedTypeException($file, 'Symfony\\Component\\HttpFoundation\\File\\File');
     }
     return $file->getPath();
 }
開發者ID:rfc1483,項目名稱:blog,代碼行數:19,代碼來源:FileToStringTransformer.php

示例3: setAvatarFile

 /**
  * Set the avatar of the object to be a specific file
  *
  * @param  File|null $file The avatar file
  * @return self
  */
 public function setAvatarFile($file)
 {
     if ($file) {
         // We don't use File's fread() because it's unavailable in less
         // recent PHP versions
         $path = $file->getPath() . '/' . $file->getFilename();
         $content = file_get_contents($path);
         $path = $this->getAvatarPath(null, false, false);
         $filename = $this->getAvatarFileName($content);
         $file->move(DOC_ROOT . $path, $filename);
         $this->setAvatar($path . $filename);
     }
     return $this;
 }
開發者ID:blast007,項目名稱:bzion,代碼行數:20,代碼來源:AvatarModel.php

示例4: testMove

 public function testMove()
 {
     $path = __DIR__ . '/Fixtures/test.copy.gif';
     $targetPath = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'test.target.gif';
     @unlink($path);
     @unlink($targetPath);
     copy(__DIR__ . '/Fixtures/test.gif', $path);
     $file = new File($path);
     $file->move($targetPath);
     $this->assertTrue(file_exists($targetPath));
     $this->assertFalse(file_exists($path));
     $this->assertEquals($targetPath, $file->getPath());
     @unlink($path);
     @unlink($targetPath);
 }
開發者ID:spf13,項目名稱:symfony,代碼行數:15,代碼來源:FileTest.php

示例5: supported

 /**
  * Validates the file as being supported by Colibri, verifying its size, extension...
  * @param $file
  * @return boolean
  * @throws \Exception
  */
 public function supported(File $file)
 {
     $filePath = $file->getPath() . DIRECTORY_SEPARATOR . $file->getFilename();
     $fileData = getimagesize($filePath);
     $maxSize = 1101004;
     // 1.05 Mo
     $mimes = array('image/jpeg', 'image/png', 'image/gif');
     $fileSize = $file->getSize();
     $fileType = $file->getMimeType();
     if ($fileSize > $maxSize) {
         throw new \Exception("File size too big. Got {$fileSize}, max {$maxSize}");
     }
     if (!in_array($fileType, $mimes)) {
         throw new \Exception("File extension not supported. Got {$fileType}.");
     }
     if ($fileData[0] > 2400 || $fileData[1] > 2400) {
         throw new \Exception("L'image est trop grande, max 2400x2400, reçu {$fileData['0']}x{$fileData['1']}px");
     }
     return true;
 }
開發者ID:sysmoh,項目名稱:colibri,代碼行數:26,代碼來源:PictureManager.php

示例6: testMoveFailing

 public function testMoveFailing()
 {
     $path = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'test.copy.gif';
     $targetPath = '/thisfolderwontexist';
     @unlink($path);
     @unlink($targetPath);
     copy(__DIR__ . '/Fixtures/test.gif', $path);
     $file = new File($path);
     try {
         $file->move($targetPath);
         $this->fail('File::move should throw an exception.');
     } catch (FileException $e) {
     }
     $this->assertFileExists($path);
     $this->assertFileNotExists($path . $targetPath . 'test.gif');
     $this->assertEquals($path, $file->getPath());
     @unlink($path);
     @unlink($targetPath);
 }
開發者ID:renegare,項目名稱:symfony,代碼行數:19,代碼來源:FileTest.php

示例7: setFile

 /**
  * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  * must be able to accept an instance of 'File' as the bundle will inject one here
  * during Doctrine hydration.
  *
  * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $newFile
  *
  * @return ProtectedFile
  */
 public function setFile(File $newFile = null)
 {
     $this->file = $newFile;
     if ($newFile) {
         // It is required that at least one field changes if you are using doctrine
         // otherwise the event listeners won't be called and the file is lost
         $this->updatedAt = new \DateTime('now');
         $this->setPath($newFile->getPath());
     }
     return $this;
 }
開發者ID:DanieleMenara,項目名稱:CreateSafe,代碼行數:22,代碼來源:ProtectedFile.php

示例8: testMoveFailing

    public function testMoveFailing()
    {
        $path = __DIR__.'/Fixtures/test.copy.gif';
        $targetPath = '/thisfolderwontexist';
        @unlink($path);
        @unlink($targetPath);
        copy(__DIR__.'/Fixtures/test.gif', $path);

        $file = new File($path);

        $this->setExpectedException('Symfony\Component\HttpFoundation\File\Exception\FileException');
        $file->move($targetPath);

        $this->assertFileExists($path);
        $this->assertFileNotExists($path.$targetPath.'test.gif');
        $this->assertEquals($path, $file->getPath());

        @unlink($path);
        @unlink($targetPath);
    }
開發者ID:nacef,項目名稱:symfony,代碼行數:20,代碼來源:FileTest.php

示例9: path

 /**
  * {@inheritdoc}
  */
 public function path()
 {
     return $this->source->getPath() . '/' . $this->source->getFilename();
 }
開發者ID:plank,項目名稱:laravel-mediable,代碼行數:7,代碼來源:FileAdapter.php


注:本文中的Symfony\Component\HttpFoundation\File\File::getPath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。