本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getRealPath方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getRealPath方法的具体用法?PHP UploadedFile::getRealPath怎么用?PHP UploadedFile::getRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getRealPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: orientate
/**
* Orientate the image.
*
* @param UploadedFile $file
* @param $orientation
* @return UploadedFile
*/
protected function orientate(UploadedFile $file, $orientation)
{
$image = imagecreatefromjpeg($file->getRealPath());
switch ($orientation) {
case 2:
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 3:
$image = imagerotate($image, 180, 0);
break;
case 4:
$image = imagerotate($image, 180, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 5:
$image = imagerotate($image, -90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 6:
$image = imagerotate($image, -90, 0);
break;
case 7:
$image = imagerotate($image, 90, 0);
imageflip($image, IMG_FLIP_HORIZONTAL);
break;
case 8:
$image = imagerotate($image, 90, 0);
break;
}
imagejpeg($image, $file->getRealPath(), 90);
return new UploadedFile($file->getRealPath(), $file->getClientOriginalName(), $file->getMimeType(), $file->getSize());
}
示例2: convertFieldValueFromForm
/**
* {@inheritdoc}
*
* @param null|\Symfony\Component\HttpFoundation\File\UploadedFile $data
*/
public function convertFieldValueFromForm($data)
{
if ($data === null) {
return null;
}
return array("inputUri" => $data->getRealPath(), "fileName" => $data->getClientOriginalName(), "fileSize" => $data->getSize());
}
示例3: saveFile
/**
* {@inheritdoc}
*/
public function saveFile(UploadedFile $uploadedFile, $fileName)
{
$stream = fopen($uploadedFile->getRealPath(), 'r+');
$result = $this->filesystem->writeStream($this->getMediaBasePath() . '/' . $fileName . '.' . $uploadedFile->guessClientExtension(), $stream);
fclose($stream);
return $result;
}
示例4: createVersionFromFile
/**
* @param AssetInterface $asset
* @param UploadedFile $file
*
* @return AssetVersion
*/
public function createVersionFromFile(AssetInterface $asset, UploadedFile $file)
{
list($width, $height) = getimagesize($file->getRealPath());
$extension = File::extension($file->getClientOriginalName(), $file->getMimetype());
$version = $this->version->create(['asset_id' => $asset->getId(), 'extension' => $extension, 'filesize' => $file->getClientSize(), 'filename' => $file->getClientOriginalName(), 'width' => $width, 'height' => $height, 'edited_at' => time(), 'edited_by' => Auth::getPerson()->getId(), 'mimetype' => $file->getMimeType(), 'metadata' => File::exif($file->getRealPath())]);
$file->move($asset->directory(), $version->id);
return $version;
}
示例5: compress
/**
* @param UploadedFile $file
* @return string
*/
public function compress(UploadedFile $file)
{
$shell = new Exec();
$command = new Command(sprintf($this->command, $file->getRealPath(), 'compressed'));
$shell->run($command);
if (!file_exists($file->getRealPath() . 'compressed')) {
throw new \RuntimeException('No compressed Image created!');
}
return $file->getRealPath() . 'compressed';
}
示例6: processFile
/**
* Process image file, make it progressive
* @param UploadedFile $file
*/
public function processFile(UploadedFile $file)
{
$this->file = $file;
foreach (self::$IMAGE_TYPES as $type) {
if (in_array($this->file->getMimeType(), $type['mime_types'])) {
$filePath = $this->file->getRealPath();
$typeObject = new $type['class']($filePath);
$typeObject->process();
break;
}
}
}
示例7: savePhoto
/**
* Save the profile photo
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
* @return Boolean
*/
public function savePhoto(UploadedFile $file)
{
if (!$file->isValid()) {
return false;
}
try {
$this->photo = md5_file($file->getRealPath());
$this->save();
Storage::disk()->put($this->photo, file_get_contents($file->getRealPath()));
return true;
} catch (\Exception $e) {
Log::error('Failed saving photo to user\'s profile: ' . $e->getMessage());
return false;
}
}
示例8: execute
public function execute()
{
if ($this->photo->isValid()) {
$name = sha1($this->user->getId() . $this->user->getLogin() . $this->user->getRegisteredAt() . time() . uniqid('ffdf'));
$photoUploader = new PhotoFormatter($this->photo->getRealPath(), self::MINIMUM_SIZE, self::MAXIMUM_SIZE, $this->output);
$old = $this->user->getAvatar();
$photoUploader->setNewName($name);
$photoUploader->loadAndScale(self::START_SIZE);
$this->user->setAvatar($name);
$this->repository->update($this->user);
if (!empty($old)) {
$photoUploader->removeOld($old, self::START_SIZE);
}
}
}
示例9: getFileMd5Name
public function getFileMd5Name(UploadedFile $file)
{
$ext = $file->guessExtension();
$md5 = md5_file($file->getRealPath());
$name = $md5 . '.' . $ext;
return $name;
}
示例10: updateUserProfileImage
/**
* 회원의 프로필 이미지를 등록한다.
*
* @param UserInterface $user 프로필 이미지를 등록할 회원
* @param UploadedFile $profileFile 프로필 이미지 파일
*
* @return string 등록한 프로필이미지 ID
*/
public function updateUserProfileImage(UserInterface $user, UploadedFile $profileFile)
{
$disk = array_get($this->profileImgConfig, 'storage.disk');
$path = array_get($this->profileImgConfig, 'storage.path');
$size = array_get($this->profileImgConfig, 'size');
// make fitted image
/** @var ImageManager $imageManager */
$imageManager = call_user_func($this->imageManagerResolver);
$image = $imageManager->make($profileFile->getRealPath());
$image = $image->fit($size['width'], $size['height']);
// remove old profile image
if (!empty($user->profileImageId)) {
$file = File::find($user->profileImageId);
if ($file !== null) {
try {
$this->storage->remove($file);
} catch (\Exception $e) {
}
}
}
// save image to storage
$id = $user->getId();
$file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk);
return $file->id;
}
示例11: __construct
/**
* Create a new job instance.
*
* @param UploadedFile $image
* @param null $filename (Without fileextension)
* @param null $folder (Format: 'example/')
*/
public function __construct(UploadedFile $image, $filename = null, $folder = null)
{
$this->realPath = $image->getRealPath();
$this->extension = $image->getClientOriginalExtension();
$this->filename = $this->getFilename($image, $filename);
$this->folder = $folder;
}
示例12: doUpload
/**
* {@inheritDoc}
*/
protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name)
{
$fs = $this->getFilesystem($mapping);
$path = !empty($dir) ? $dir . '/' . $name : $name;
$stream = fopen($file->getRealPath(), 'r+');
$fs->writeStream($path, $stream, array('mimetype' => $file->getMimeType()));
}
示例13: store
public function store(UploadedFile $file)
{
$file->getClientOriginalName();
$fileResult = \DB::table('file')->where('name', $file->getClientOriginalName())->where('checksum', md5_file($file->getRealPath()))->first();
if (isset($fileResult->id)) {
return $fileResult;
}
$fileResult = new Models\file();
$fileResult->name = $file->getClientOriginalName();
$fileResult->size = $file->getSize();
$fileResult->mime_type = $file->getMimeType();
$fileResult->checksum = md5_file($file->getRealPath());
$fileResult->save();
$fileResult->path = $this->moveFile($file, $fileResult->id);
$fileResult->save();
return $fileResult;
}
示例14: uploadSingleFile
/**
* Upload a single file.
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
*
* @param string $target
* @return string
*/
protected function uploadSingleFile($file, $target = null)
{
$filename = uniqid() . '.' . $file->getClientOriginalExtension();
$filename = $target ? $target . '/' . $filename : $filename;
$content = file_get_contents($file->getRealPath());
$this->flysystem->write($filename, $content);
return cloudfront_asset($filename);
}
示例15: saveUploadedFile
/**
* @param string $containerName
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
* @param string|null $relativePath
*
* @return bool
*/
public function saveUploadedFile($containerName, UploadedFile $file, $relativePath)
{
if ($file->isValid() === false) {
return false;
}
$fileName = $file->getClientOriginalName();
$filePath = $this->getFullFileName($containerName, $fileName);
return $this->move($file->getRealPath(), $filePath);
}