本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getClientOriginalName方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getClientOriginalName方法的具体用法?PHP UploadedFile::getClientOriginalName怎么用?PHP UploadedFile::getClientOriginalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getClientOriginalName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleUploadedFile
/**
* Handles an uploaded file by putting it in the $targetDir.
*
* @param UploadedFile $uploadedFile File object that has been uploaded - usually taken from Request object.
* @param string $targetDir [optional] Where to (relatively to the storage root dir) put the file?
* @param array $allowed [optional] What files are allowed? If not matching then will throw exception.
* @param int $maxFileSize [optional] What is the maximum allowed file size for this file?
* @return File
*/
public function handleUploadedFile(UploadedFile $uploadedFile, $targetDir = '/', array $allowed = array(), $maxFileSize = 0)
{
array_walk($allowed, function ($ext) {
return strtolower($ext);
});
$targetDir = trim($targetDir, '/');
$targetDir = $this->path . $targetDir . (empty($targetDir) ? '' : '/');
$filenameElements = explode('.', $uploadedFile->getClientOriginalName());
$extension = array_pop($filenameElements);
$extension = strtolower($extension);
$filename = implode('.', $filenameElements);
$targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
$targetPath = $targetDir . $targetName;
// create unique file name
while (file_exists($targetPath)) {
$targetName = StringUtils::fileNameFriendly($filename . '-' . StringUtils::random() . '.' . $extension);
$targetPath = $targetDir . $targetName;
}
// basic check for allowed type
if (!empty($allowed) && !in_array($extension, $allowed)) {
throw new FileException('The uploaded file is not of a valid type (allowed: ' . implode(', ', $allowed) . ').');
}
// basic check for max allowed size
if ($maxFileSize && $uploadedFile->getSize() > $maxFileSize) {
throw new FileException('The uploaded file is too big (max allowed size is ' . StringUtils::bytesToString($maxFileSize) . ').');
}
try {
$movedFile = $uploadedFile->move(rtrim($targetDir, '/'), $targetName);
} catch (SfFileException $e) {
// if exception thrown then convert it to our exception
throw new FileException($e->getMessage(), $e->getCode());
}
$file = $this->convertSfFileToStorageFile($movedFile);
return $file;
}
示例2: 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());
}
示例3: 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());
}
示例4: handleUpload
/**
* @param UploadedFile|null $uploadedFile
* @param array $options
* @return AssetFile
*/
public function handleUpload(UploadedFile $uploadedFile = null, array $options = [])
{
$resolver = new OptionsResolver();
$resolver->setDefaults(['type' => null, 'fallbackType' => null, 'targetUri' => null])->setAllowedTypes(['type' => ['string', 'null'], 'fallbackType' => ['int', 'null'], 'targetUri' => ['string', 'null']])->setAllowedValues(['type' => ['image', 'audio', 'file', null]]);
$options = $resolver->resolve($options);
if (!$uploadedFile instanceof UploadedFile || !$uploadedFile->isValid() || !($assetFile = new AssetFile($uploadedFile, null, $options['fallbackType'])) || $assetFile->getType() === null) {
throw new \RuntimeException('Invalid uploaded file');
}
$assetFile->setOriginalName($uploadedFile->getClientOriginalName());
if ($options['type'] !== null) {
$this->validateAssetFileType($assetFile, $options['type']);
}
if ($options['targetUri'] !== null) {
$uploadsDir = $this->assetsResolver->uriToPath($options['targetUri']);
} else {
$uploadsDir = $this->assetsResolver->assetPath($assetFile->getType());
}
$tempFile = $uploadedFile->move($uploadsDir, $this->getTargetFileName($uploadedFile->getClientOriginalName(), $uploadsDir));
$assetFile->setFile($tempFile);
$uri = $this->assetsResolver->pathToUri($assetFile->getFile()->getPathname());
if ($uri === null) {
throw new \RuntimeException('Unable to retrieve uploaded file uri');
}
$assetFile->setUri($uri);
return $assetFile;
}
示例5: 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;
}
示例6: moveFile
private function moveFile(UploadedFile $file, $id)
{
$destinationPath = $this->getDestinationPath() . '/' . $this->getPathById($id);
if ($file->move($destinationPath, $file->getClientOriginalName())) {
return $this->getPathById($id) . '/' . $file->getClientOriginalName();
}
return '';
}
示例7: preUpload
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if (null === $this->file) {
return;
}
$this->url = $this->file->guessExtension();
$this->alt = $this->file->getClientOriginalName();
}
示例8: uniqueName
/**
* For files, we won't generate a very random name,
* so we can easily.
*
*
*/
protected function uniqueName()
{
$filename = $this->file->getClientOriginalName();
$filename = str_replace(' ', '-', $filename);
$pieces = explode('.', $filename);
array_pop($pieces);
return implode('.', $pieces);
}
示例9: fileName
/**
* Get the file name for the photo
*
* @return string
*/
public function fileName()
{
if (!is_null($this->name) && $this->name) {
return $this->name;
}
$name = sha1($this->file->getClientOriginalName() . '-' . microtime());
$extension = $this->file->getClientOriginalExtension();
return "{$name}.{$extension}";
}
示例10: upload
public function upload()
{
if (null === $this->file) {
return;
}
$name = $this->file->getClientOriginalName();
$this->file->move($this->getUploadRootDir(), $name);
$this->url = $name;
}
示例11: getFileFromChunks
/**
* Check if all chunks of a file being uploaded have been received
* If yes, return the name of the reassembled temporary file
*
* @param UploadedFile $uploadedFile
*
* @return UploadedFile|null
*/
public function getFileFromChunks(UploadedFile $uploadedFile)
{
$filename = time() . '-' . $uploadedFile->getClientOriginalName();
$path = $this->tmpDir . DIRECTORY_SEPARATOR . $filename;
if (FlowBasic::save($path, $this->tmpDir)) {
return new UploadedFile($path, $uploadedFile->getClientOriginalName(), $uploadedFile->getClientMimeType());
}
return null;
}
示例12: makeFileRecord
/**
* Create a base file model class
*
* @return File
*/
protected function makeFileRecord()
{
$file = new File();
$file->fileable_type = $this->fileable_type;
$file->fileable_id = $this->fileable_id;
$file->filename = $this->timestamp . '-' . $this->file->getClientOriginalName();
$file->filetype = $this->file->getClientMimeType();
$file->filepath = $file->getURLPath() . $file->filename;
$file->order = 0;
return $file;
}
示例13: run
public function run(UploadedFile $file, MediaProvider $media)
{
$media->ext = $file->getClientOriginalExtension();
$media->path = $file->getPath();
// by default /tmp
$media->file = $file->getClientOriginalName();
$media->meta = empty($media->meta) ? [] : $media->meta;
$media->sizes = empty($media->sizes) ? [] : $media->sizes;
$media->caption = $file->getClientOriginalName();
$media->alt = $file->getClientOriginalName();
}
示例14: preUpload
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
// Si jamais il n'y a pas de fichier (champ facultatif)
if (null === $this->file) {
return;
}
// Le nom du fichier est son id, on doit juste stocker �galement son extension
// Pour faire propre, on devrait renommer cet attribut en � extension �, plut�t que � extension �
$this->extension = $this->file->guessExtension();
// Et on g�n�re l'attribut alt de la balise <img>, � la valeur du nom du fichier sur le PC de l'internaute
$this->alt = $this->file->getClientOriginalName();
}
示例15: playTorrentFileAction
public function playTorrentFileAction(Request $request)
{
$file = $_FILES['torrentFile'];
$type = $_POST['torrentFileType'];
$filename = $_POST['torrentFileName'];
$uploadedFile = new UploadedFile($file['tmp_name'], $filename, $type);
$moveTo = $this->get('kernel')->getRootDir() . '/cache/' . $this->get('kernel')->getEnvironment();
$uploadedFile->move($moveTo, $uploadedFile->getClientOriginalName());
$streamerService = $this->get('homesoft_torrent_streamer.torrent_streamer');
$response = array('status' => true, 'url' => $streamerService->startStreamer($moveTo . '/' . $uploadedFile->getClientOriginalName()));
return new JsonResponse($response);
}