当前位置: 首页>>代码示例>>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;未经允许,请勿转载。