本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\File::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getSize方法的具体用法?PHP File::getSize怎么用?PHP File::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\File
的用法示例。
在下文中一共展示了File::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: replaceFromFilesystem
/**
* Replaces the current file with a new file.
*
* @param UploadedFile $file The target file
* @param File $filesystemFile The source file
*/
public function replaceFromFilesystem(UploadedFile $file, File $filesystemFile)
{
$file->setOriginalFilename($filesystemFile->getBasename());
$file->setExtension($filesystemFile->getExtension());
$file->setMimeType($filesystemFile->getMimeType());
$file->setSize($filesystemFile->getSize());
$storage = $this->getStorage($file);
if ($filesystemFile->getSize() > $this->container->get("partkeepr_systemservice")->getFreeDiskSpace()) {
throw new DiskSpaceExhaustedException();
}
$storage->write($file->getFullFilename(), file_get_contents($filesystemFile->getPathname()), true);
}
示例2: setFileAttribute
public function setFileAttribute(\Symfony\Component\HttpFoundation\File\File $file)
{
$this->attributes['file'] = $file;
$this->original_name = $file instanceof UploadedFile ? $file->getClientOriginalName() : $file->getFilename();
$this->size = $file->getSize();
$this->content_type = $file->getMimeType();
}
示例3: __construct
/**
* Constructor.
*
* @param File $file A File instance
*/
public function __construct(File $file)
{
if ($file instanceof UploadedFile) {
parent::__construct($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true);
} else {
parent::__construct($file->getPathname(), $file->getBasename(), $file->getMimeType(), $file->getSize(), 0, true);
}
}
示例4: setFile
/**
* @param File|null $file
*/
public function setFile(File $file = null)
{
$this->file = $file;
$this->fileMimeType = $this->file->getMimeType();
$this->fileSize = $this->file->getSize();
if ($this->file instanceof UploadedFile) {
$this->fileOriginalName = $this->file->getClientOriginalName();
}
// dump($this);
}
示例5: __construct
/**
* @param string|null $pathname
*/
public function __construct($pathname = null)
{
$this->pathname = $pathname;
if ($pathname) {
$file = new SfFile($pathname);
$this->name = $file->getBasename();
$this->id = $this->name;
$this->mimeType = $file->getMimeType();
$this->size = $file->getSize();
}
}
示例6: fromFile
/**
* Creates a file object from a file on the disk.
*/
public function fromFile($filePath)
{
if ($filePath === null) {
return;
}
$file = new FileObj($filePath);
$this->file_name = $file->getFilename();
$this->file_size = $file->getSize();
$this->content_type = $file->getMimeType();
$this->disk_name = $this->getDiskName();
$this->putFile($uploadedFile->getRealPath(), $this->disk_name);
}
示例7: setFile
/**
* Set file.
*
* @param UploadedFile $file
*
* @return $this
*/
public function setFile(UploadedFile $file = null)
{
$this->file = $file;
$this->setUpdatedAt(new \DateTime());
if ($file) {
$this->mimeType = $file->getMimeType();
$this->fileSize = $file->getSize();
} else {
$this->mimeType = null;
$this->fileSize = null;
}
return $this;
}
示例8: create
/**
* {@inheritDoc}
*/
public function create(File $file)
{
$mc = $this->getMediaClass();
$baseFile = new $mc();
$baseFile->setPath($file->getPathname());
$baseFile->setName($file->getClientOriginalName());
if ($baseFile instanceof BaseFile) {
$baseFile->setCreatedAt(new \DateTime());
$baseFile->setSize($file->getSize());
$baseFile->setContentType($file->getMimeType());
}
return $baseFile;
}
示例9: testSizeFailing
public function testSizeFailing()
{
$dir = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'directory';
$path = $dir . DIRECTORY_SEPARATOR . 'test.copy.gif';
@unlink($path);
copy(__DIR__ . '/Fixtures/test.gif', $path);
$file = new File($path);
@unlink($path);
try {
$file->getSize();
$this->fail('File::getSize should throw an exception.');
} catch (FileException $e) {
}
}
示例10: prepareResponse
private function prepareResponse(File $file, $filename = null)
{
$mimeType = $file->getMimeType();
if ($mimeType == 'application/pdf') {
$disposition = 'inline';
} else {
$disposition = 'attachment';
}
$response = new Response();
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-Type', $mimeType);
$response->headers->set('Content-Disposition', $disposition . '; filename="' . ($filename ? $filename : $file->getFilename()) . '"');
$response->headers->set('Content-Length', $file->getSize());
$response->sendHeaders();
readfile($file);
return $response;
}
示例11: VisualAction
public function VisualAction($document)
{
// Generate response
$response = new Response();
// Set headers
$filepath = $this->get('kernel')->getRootDir() . "/uploads/formations_documents/" . $document;
$oFile = new File($filepath);
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', $oFile->getMimeType());
$response->headers->set('Content-Disposition', 'inline; filepath="' . $oFile->getBasename() . '";');
$response->headers->set('Content-length', $oFile->getSize());
// filename
// Send headers before outputting anything
$response->sendHeaders();
$response->setContent(file_get_contents($filepath));
return $response;
}
示例12: GetFile
/**
* @Route("/files/{fileName}")
* @Method("GET")
*/
public function GetFile($fileName)
{
$finder = new Finder();
$finder->files()->name($fileName)->in('../data');
if ($finder->count() == 0) {
return new Response("File " . $fileName . " not found", 404);
}
$iterator = $finder->getIterator();
$iterator->rewind();
$file = $iterator->current();
$oFile = new File(realpath($file));
$response = new Response(null);
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', $oFile->getMimeType());
$response->headers->set('Content-Disposition', 'attachment; filename="' . $oFile->getBasename() . '";');
$response->headers->set('Content-length', $oFile->getSize());
$response->setContent(file_get_contents($oFile));
return $response;
}
示例13: beforePrepare
/**
* Add parameters Kinvey needs to properly process the file.
*
* @param Guzzle\Common\Event
* @return void
*/
public function beforePrepare(Event $event)
{
$command = $event['command'];
$operation = $command->getOperation();
$client = $command->getClient();
if ($command->getName() !== 'createEntity') {
return;
}
if ($command['collection'] !== 'files' && $client->getCollectionName() !== 'files') {
return;
}
$file = new File($command['path']);
$operation->setResponseClass('GovTribe\\LaravelKinvey\\Client\\KinveyFileResponse');
$operation->addParam(new Parameter(array('name' => 'path', 'type' => 'string', 'default' => $command['path'])));
$operation->addParam(new Parameter(array('name' => '_public', 'location' => 'json', 'type' => 'boolean', 'default' => isset($command['_public']) ? $command['_public'] : false)));
$operation->addParam(new Parameter(array('name' => '_filename', 'location' => 'json', 'type' => 'string', 'default' => !isset($command['_filename']) ? $file->getBaseName() : $command['_filename'])));
$operation->addParam(new Parameter(array('name' => 'size', 'location' => 'json', 'type' => 'integer', 'default' => $file->getSize())));
$operation->addParam(new Parameter(array('name' => 'mimeType', 'location' => 'json', 'type' => 'string', 'default' => $file->getMimeType())));
}
示例14: getPhotoAction
/**
*
* @param $photo_file
* @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
*/
public function getPhotoAction($photo_id)
{
if (!$this->getUser()) {
return $this->redirectToRoute('fos_user_security_login');
}
$photo_file = $this->get('doctrine')->getRepository('IuchBundle:Photo')->findOneById($photo_id)->getNom();
// Generate response
$response = new Response();
$filepath = $this->get('kernel')->getRootDir() . "/uploads/photos/" . $photo_file;
$photoFile = new File($filepath);
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', $photoFile->getMimeType());
$response->headers->set('Content-Disposition', 'inline; filepath="' . $photoFile->getBasename() . '";');
$response->headers->set('Content-length', $photoFile->getSize());
// Send headers before outputting anything
$response->sendHeaders();
$response->setContent(file_get_contents($filepath));
return $response;
}
示例15: createLayout
protected function createLayout($lang)
{
$layout = new Layout($lang, "default-{$lang}");
$logoPath = $this->getContainer()->get('kernel')->getRootDir() . '/../web/bundles/donatefront/images/logo.png';
$bgPath = $this->getContainer()->get('kernel')->getRootDir() . '/../web/bundles/donatefront/images/fd-body.jpg';
$f = new File($logoPath);
$logo = new UploadedFile($logoPath, 'ulogo.png', $f->getMimeType(), $f->getSize());
$f = new File($bgPath);
$bg = new UploadedFile($bgPath, 'ubg.png', $f->getMimeType(), $f->getSize());
$layout->setLogo($logo);
$layout->setBackground($bg);
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$repo = $em->getRepository('DonateCoreBundle:Layout');
$defaultLayout = $repo->findDefaultLayout($lang);
if (count($defaultLayout) == 0) {
$layout->setIsDefault(true);
}
return $layout;
}