本文整理汇总了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());
}
示例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();
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例9: path
/**
* {@inheritdoc}
*/
public function path()
{
return $this->source->getPath() . '/' . $this->source->getFilename();
}