本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\File::getClientOriginalName方法的典型用法代码示例。如果您正苦于以下问题:PHP File::getClientOriginalName方法的具体用法?PHP File::getClientOriginalName怎么用?PHP File::getClientOriginalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\File
的用法示例。
在下文中一共展示了File::getClientOriginalName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getName
/**
* Get original name of file.
*
* @return string
*/
public function getName()
{
if ($this->file instanceof UploadedFile) {
return $this->file->getClientOriginalName();
}
return $this->file->getFilename();
}
示例2: preUpload
public function preUpload()
{
if (null !== $this->file) {
// do whatever you want to generate a unique name
$this->file_name = $this->file->getClientOriginalName();
$this->charte_file = uniqid() . '.' . $this->file->guessExtension();
}
}
示例3: upload
/**
* @throws FileException
*/
public function upload()
{
if ($this->file instanceof File) {
$name = sha1($this->file->getClientOriginalName() . uniqid() . getrandmax()) . '.' . $this->file->guessExtension();
$this->file->move($this->getWeb() . $this->folder, $name);
$this->file = $name;
} else {
throw new FileException('It must be a Symfony\\Component\\HttpFoundation\\File\\File instance');
}
}
示例4: 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();
}
示例5: __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);
}
}
示例6: saveFile
/**
* Save uploaded file without validation
*
* @param File $file
* @param string $newLocation
* @param string $newName
* @throws FileException
* @return File
*/
protected function saveFile(File $file, $newLocation, $newName = "")
{
$name = $file->getClientOriginalName();
if ($newName) {
$name = $newName;
}
return $file->move($this->createFolderIfNotExist($newLocation), $this->getUniqueFileName($name, $newLocation));
}
示例7: storeFileInPath
public function storeFileInPath($path, File $file, $name = null)
{
$filename = $name ? $name : $file->getClientOriginalName();
for ($i = 2; file_exists($path . $filename); $i++) {
$filename = $i . '_' . $filename;
}
$file->move($path, $filename);
return $filename;
}
示例8: 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);
}
示例9: 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;
}
示例10: validateFileExtension
protected function validateFileExtension(File $file, $extensions)
{
if ($file instanceof UploadedFile) {
$filename = $file->getClientOriginalName();
} else {
$filename = $file->getFilename();
}
$errors = array();
$regex = '/\\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
if (!preg_match($regex, $filename)) {
$errors[] = "只允许上传以下扩展名的文件:" . $extensions;
}
return $errors;
}
示例11: getNormalizedFilename
/**
* @param File $file
* @return string
*/
protected function getNormalizedFilename(File $file)
{
if ($file instanceof UploadedFile) {
$originalFilename = $file->getClientOriginalName();
$size = $file->getClientSize();
} else {
$originalFilename = $file->getFilename();
$size = $file->getSize();
}
$name = preg_replace(self::REGEX_FILENAME_EXT, '', $originalFilename);
$name = preg_replace(self::REGEX_INVALID_FILENAME_CHARS, '_', $name);
$hash = substr(sha1(json_encode(array(time(), $name, $size))), 0, 7);
$ext = $file->getExtension();
if (!$ext) {
$ext = explode('.', $originalFilename);
$ext = end($ext);
}
$filename = sprintf('%s_%s.%s', $name, $hash, $ext);
return $filename;
}
示例12: 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);
}
示例13: getTargetFileName
/**
* Get the full target name for the uploaded file.
*
* @return string
*/
protected function getTargetFileName()
{
if ($this->final) {
return $this->fileName;
}
// Create a unique filename with a simple pattern
$originalName = $this->file->getClientOriginalName();
$extension = $this->file->guessExtension() ?: pathinfo($originalName, PATHINFO_EXTENSION);
$pattern = $this->getTargetFileNamePattern();
$fileName = sprintf($pattern, pathinfo($originalName, PATHINFO_FILENAME), $extension);
$this->fullPath = $this->getTargetFileDirectory() . DIRECTORY_SEPARATOR . $fileName;
$i = 1;
while (file_exists($this->fullPath)) {
$fileName = sprintf($pattern, pathinfo($originalName, PATHINFO_FILENAME) . "({$i})", $extension);
$this->fullPath = $this->getTargetFileDirectory() . DIRECTORY_SEPARATOR . $fileName;
$i++;
}
$this->app['logger.system']->debug("[BoltForms] Setting uploaded file '{$originalName}' to use the name '{$fileName}'.", array('event' => 'extensions'));
$this->final = true;
return $this->fileName = $fileName;
}
示例14: preUpload
public function preUpload()
{
if (null !== $this->getFile()) {
// set the asset title as original file name if title is missing
if (null === $this->getTitle()) {
$this->setTitle($this->file->getClientOriginalName());
}
$filename = sha1(uniqid(mt_rand(), true));
$extension = $this->getFile()->guessExtension();
if (empty($extension)) {
//get it from the original name
$extension = pathinfo($this->originalFileName, PATHINFO_EXTENSION);
}
$this->path = $filename . '.' . $extension;
} elseif ($this->getStorageLocation() == 'remote' && $this->getRemotePath() !== null) {
$fileName = basename($this->getRemotePath());
$this->setOriginalFileName($fileName);
// set the asset title as original file name if title is missing
if (null === $this->getTitle()) {
$this->setTitle($fileName);
}
}
}
示例15: setFile
/**
* Sets file.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
*/
public function setFile(File $file = null)
{
$this->file = $file;
if ($file) {
// 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->fileType = strtoupper($file->getExtension());
$this->size = $file->getSize();
if ($file instanceof \Symfony\Component\HttpFoundation\File\UploadedFile) {
$this->originalName = $file->getClientOriginalName();
if ($this->isNoname) {
$this->name = $this->originalName;
}
}
}
}