本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\File::getRealPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getRealPath方法的具體用法?PHP File::getRealPath怎麽用?PHP File::getRealPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\HttpFoundation\File\File
的用法示例。
在下文中一共展示了File::getRealPath方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: run
public function run(File $file)
{
$image = $this->intervention->make($file->getRealPath());
$image->orientate();
$image->save(null, 100);
$image->destroy();
}
示例2: process
public function process(File $file, Image $image)
{
$imageData = $this->intervention->make($file->getRealPath());
$imageData->brightness($this->brightness);
$imageData->blur($this->blur);
$imageData->save(null, $this->compression);
}
示例3: downloadAction
/**
*
* @param string $uid
*
* @return StreamedResponse|RedirectResponse
*/
public function downloadAction($uid)
{
$urlFrom = $this->getReferer();
if (null == $urlFrom || trim($urlFrom) == '') {
$urlFrom = $this->generateUrl('_info_homepage');
}
$em = $this->getEntityManager();
try {
$biDoc = $em->getRepository('AcfDataBundle:BiDoc')->find($uid);
if (null == $biDoc) {
$logger = $this->getLogger();
$logger->addError('Document inconnu');
$this->flashMsgSession('warning', $this->translate('BiDoc.download.notfound'));
} else {
$biDocDir = $this->getParameter('kernel.root_dir') . '/../web/res/biDocs';
$fileName = $biDoc->getFileName();
try {
$dlFile = new File($biDocDir . '/' . $fileName);
$response = new StreamedResponse(function () use($dlFile) {
$handle = fopen($dlFile->getRealPath(), 'r');
while (!feof($handle)) {
$buffer = fread($handle, 1024);
echo $buffer;
flush();
}
fclose($handle);
});
$timestamp = $biDoc->getDtUpdate()->getTimestamp();
$response->headers->set('Content-Type', $biDoc->getMimeType());
$response->headers->set('Cache-Control', '');
$response->headers->set('Content-Length', $biDoc->getSize());
$response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', $timestamp));
$fallback = $this->normalize($biDoc->getTitle());
$contentDisposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $biDoc->getOriginalName(), $fallback);
$response->headers->set('Content-Disposition', $contentDisposition);
$biDoc->setNbrDownloads($biDoc->getNbrDownloads() + 1);
$em->persist($biDoc);
$em->flush();
return $response;
} catch (FileNotFoundException $fnfex) {
$logger = $this->getLogger();
$logger->addError('Fichier introuvable ou autre erreur');
$logger->addError($fnfex->getMessage());
$this->flashMsgSession('error', $fnfex->getMessage());
$this->flashMsgSession('warning', $this->translate('BiDoc.download.notfound'));
}
}
} catch (\Exception $e) {
$logger = $this->getLogger();
$logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
$this->flashMsgSession('error', $e->getMessage());
$this->flashMsgSession('warning', $this->translate('BiDoc.download.notfound'));
}
return $this->redirect($urlFrom);
}
示例4: import
/**
* @param File $file
* @param Administration $administration
* @return array
*
* @throws InvalidBankAccountException
* @throws InvalidCurrencyException
*/
public function import(File $file, Administration $administration)
{
$return = array();
if (($handle = fopen($file->getRealPath(), "r")) !== FALSE) {
while (($row = fgetcsv($handle)) !== FALSE) {
$return[] = $this->createTransactionFromRow($row, $administration);
}
fclose($handle);
}
return $return;
}
示例5: process
public function process(File $file, Image $image, array $config = null)
{
$imageData = Intervention::make($file->getRealPath());
$preserveRatio = $this->preserveRatio;
$imageData->resize($this->width, $this->height, function ($constraint) use($preserveRatio) {
if ($preserveRatio) {
$constraint->aspectRatio();
}
});
$imageData->save(null, 100);
}
示例6: process
public function process(File $file, Image $image, array $config = null)
{
$imageData = Intervention::make($file->getRealPath());
// Sections override origin data.
if ($this->section) {
// ToDo: Add parameter to calculate crops by section.
return;
} else {
$imageData->crop($this->width, $this->height, $this->originTop, $this->originLeft);
}
$imageData->save(null, 100);
}
示例7: run
public function run(File $file)
{
$image = $this->intervention->make($file->getRealPath());
$preserveRatio = $this->preserveRatio;
$image->resize($this->width, $this->height, function ($constraint) use($preserveRatio) {
if ($preserveRatio) {
$constraint->aspectRatio();
}
});
$image->save(null, 100);
$image->destroy();
}
示例8: 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($file->getRealPath(), $this->disk_name);
return $this;
}
示例9: getImageThumb
/**
* @param File|null $image
* @param $image_type
* @return \Imagine\Image\ImageInterface
*/
public function getImageThumb(File $image = null, $image_type, $image_area = null)
{
if (isset($this->image_types[$image_type])) {
$source = $this->imagine->open($image->getRealPath());
$this->preProcessSourceImg($source);
$this->preProcessCropArea($source, $image_area);
$type = $this->image_types[$image_type];
$transformer_class = self::TRANSFORMER_CLASS_PATH . "\\" . Inflector::classify($type['transform']) . 'Transformer';
$width = isset($type['width']) ? $type['width'] : null;
$height = isset($type['height']) ? $type['height'] : null;
/** @var $transformer TransformerInterface */
$transformer = new $transformer_class($this->imagine, $source, $width, $height);
$retval = $transformer->getTransformed();
} else {
throw new ResourceNotFoundException("Can't show image!");
}
return $retval->strip();
}
示例10:
function it_is_configurable(File $file)
{
$file->getRealPath()->willReturn('/path/to/file/img.jpg');
$this->getFilePath()->shouldReturn(null);
$this->isMultiple()->shouldReturn(false);
$this->getCodeField()->shouldReturn('code');
$this->isUploadAllowed()->shouldReturn(false);
$this->setFilePath('/path/to/file/');
$this->setMultiple(true);
$this->setCodeField('custom_code');
$this->setUploadAllowed(true);
$this->getFilePath()->shouldReturn('/path/to/file/');
$this->isMultiple()->shouldReturn(true);
$this->getCodeField()->shouldReturn('custom_code');
$this->isUploadAllowed()->shouldReturn(true);
$this->setUploadedFile($file);
$this->getFilePath()->shouldReturn('/path/to/file/img.jpg');
}
示例11: uploadImage
/**
* Enregistre l'icône sur le disque.
*
* @return void
*/
protected function uploadImage()
{
$this->deleteImage();
$this->miniature = null;
$fichier = new Fichier($this->imageFile->getRealPath());
$this->image = $this->imageFile->getClientOriginalName();
$this->dossier = $this->guessSousDossier();
$fichier->move($this->getImageUploadDir() . DIRECTORY_SEPARATOR . $this->image, false);
$image = new Image($fichier->getChemin());
$image->setNomMinifie($this->getTitle(), '-', true, 128);
$this->image = $image->getNom();
if ($image->getLargeur() >= $image->getHauteur() && $image->getLargeur() > $this->getLargeurMaximale()) {
$image->redimensionne($this->getLargeurMaximale(), null, true);
} elseif ($image->getLargeur() < $image->getHauteur() && $image->getHauteur() > $this->getHauteurMaximale()) {
$image->redimensionne(null, $this->getHauteurMaximale(), true);
}
$this->largeur = $image->getLargeur();
$this->hauteur = $image->getHauteur();
$this->setImageFile(null);
}
示例12: fromFile
public function fromFile($src, $target_quality = 90)
{
$imageFileName = strtok(str_replace(appHomeUrl() . '/storage/app/tmp/', '', $src), '?');
if (startWith($imageFileName, self::getPrefix())) {
$file = new File(storage_path('app/tmp/' . $imageFileName));
if ($file) {
$this->targetFileAsset = asset('storage/app/tmp/' . $imageFileName);
$this->imageType = $file->getMimeType();
$this->imageFilePath = $file->getRealPath();
switch (strtolower($this->imageType)) {
case 'image/png':
$this->imageFileExt = 'png';
$this->image = imagecreatefrompng($this->imageFilePath);
break;
case 'image/gif':
$this->imageFileExt = 'gif';
$this->image = imagecreatefromgif($this->imageFilePath);
break;
case 'image/jpeg':
case 'image/pjpeg':
$this->imageFileExt = 'jpg';
$this->image = imagecreatefromjpeg($this->imageFilePath);
break;
default:
$this->saveResult(['success' => false, 'message' => 'Image type was not supported']);
return false;
}
$this->imageFileSize = $file->getSize();
$this->targetQuality = $target_quality;
list($imageWidth, $imageHeight) = getimagesize($this->imageFilePath);
$this->imageWidth = $imageWidth;
$this->imageHeight = $imageHeight;
$this->targetFileName = $imageFileName;
$this->targetFilePath = $this->imageFilePath;
return true;
}
}
$this->saveResult(['success' => false, 'message' => 'Image was not existed']);
return false;
}
示例13: imageResize
/**
* imageResize
*
* @param File $file
* @param int $maxWidth
* @param int $maxHeight
* @param bool $enlarge
* @param bool $keepRatio
*
* @return ImageInterface|File|static
*/
protected function imageResize(File $file, $maxWidth, $maxHeight, $enlarge = false, $keepRatio = true)
{
if ($maxWidth == 0 && $maxHeight == 0) {
return $file;
} elseif ($maxHeight == 0) {
$maxHeight = $maxWidth;
} elseif ($maxWidth == 0) {
$maxWidth = $maxHeight;
}
$imagine = new Imagine();
$resizeImg = $imagine->open($file->getRealPath());
//get the size of the image you're resizing.
$origHeight = $resizeImg->getSize()->getHeight();
$origWidth = $resizeImg->getSize()->getWidth();
if ($keepRatio) {
//check for longest side, we'll be seeing that to the max value above
if ($origHeight > $origWidth) {
$newWidth = $maxHeight * $origWidth / $origHeight;
$newHeight = $maxHeight;
} else {
$newHeight = $maxWidth * $origHeight / $origWidth;
$newWidth = $maxWidth;
}
} else {
$newWidth = $maxWidth;
$newHeight = $maxHeight;
}
//dont enlarge small images
if (!$enlarge) {
if ($origHeight > $origWidth && $newHeight > $origHeight || $newWidth > $origWidth) {
return $file;
}
}
$size = new Box($newWidth, $newHeight);
$resizeImg->resize($size)->save($file->getRealPath());
return $file;
}
示例14: __construct
public function __construct(File $file, FFMpeg $ffmpeg)
{
$this->video = $ffmpeg->open($file->getRealPath());
}
示例15: createImageRecord
/**
* Create the database entry for an image.
*
* @param File $image
* @param array $attributes
* @return Image
*/
protected function createImageRecord(File $image, array $attributes = [])
{
// Obtain image metadata and save the record to the database.
$imageData = new ImageData($image, $this->intervention->make($image->getRealPath()));
$attributes = array_merge($attributes, ['width' => $imageData->getWidth(), 'height' => $imageData->getHeight(), 'average_color' => $imageData->getAveragePixelColor(), 'mime_type' => $image->getMimeType()]);
return $this->imageRepository->create($attributes);
}