本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::guessExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::guessExtension方法的具体用法?PHP UploadedFile::guessExtension怎么用?PHP UploadedFile::guessExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::guessExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Execute the job.
*/
public function handle()
{
/**
* Create Extra
* @var Extra $extra
*/
$extra = $this->product->extras()->create($this->data);
$aspectDir = @$this->data['aspect_ratio'] ?: '16x9';
/**
* Move Extra Content to folder
*/
$path = '/image/products-extras/';
$extraID = $extra->getAttribute('id');
$productCode = $this->product->getAttribute('code');
$filename = $productCode . '-extra-image-' . $extraID . '.' . $this->image->guessExtension();
$image = $this->image->move(base_path() . $path, $filename);
$extra->setAttribute('image', $path . $filename);
$filename = $productCode . '-extra-video-' . $extraID . '.' . $this->video->guessExtension();
$video = $this->video->move(base_path() . $path . $aspectDir . '/', $filename);
$extra->setAttribute('video', $filename);
$extra->save();
/**
* Announce ExtraWasCreated
*/
event(new ExtraWasCreated($extra));
}
示例2: preUpload
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if (null === $this->file) {
return;
}
$this->url = $this->file->guessExtension();
$this->alt = $this->file->getClientOriginalName();
}
示例3: 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();
}
示例4: preUpload
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
// if (null !== $this->getFile()) {
// // do whatever you want to generate a unique name
// $filename = sha1(uniqid(mt_rand(), true));
// $this->path = $filename.'.'.$this->getFile()->guessExtension();
// }
if (null !== $this->file) {
// faites ce que vous voulez pour générer un nom unique
$this->path = sha1(uniqid(mt_rand(), true)) . '.' . $this->file->guessExtension();
}
}
示例5: validateFile
/**
* Determines whether a passed photo file
* is valid.
* @throws InalidMediaTypeException If the file extension isn't jpeg, jpg, png, bmp or gif
*
* @param Symfony\Component\HttpFoundation\File\UploadedFile $file
* @return boolean
*/
public function validateFile(File $file)
{
// if ( ! $file->isValid())
// {
// throw new PhotoUploadException('error occured while uploading photo' , $file->getError());
// }
$input = ['extension' => $file->guessExtension()];
$rules = ['extension' => 'in:jpeg,jpg,png,bmp,gif'];
$validation = $this->validator->make($input, $rules);
if ($validation->fails()) {
throw new InvalidMediaTypeException($file->guessExtension());
}
return true;
}
示例6: copyFile
/**
* Make 3 copy from original user avatar with compression: small, medium and big
* @param iUser $user
*/
public function copyFile(iUser $user)
{
// move file to original folder
$upload = $this->file->move(root . '/upload/user/avatar/original/', $user->id . '.' . $this->file->guessExtension());
try {
// big image
$this->resizeAndSave($upload, $user->id, 'big');
$this->resizeAndSave($upload, $user->id, 'medium');
$this->resizeAndSave($upload, $user->id, 'small');
} catch (\Exception $e) {
if (App::$Debug) {
App::$Debug->addException($e);
}
}
}
示例7: getFileMd5Name
public function getFileMd5Name(UploadedFile $file)
{
$ext = $file->guessExtension();
$md5 = md5_file($file->getRealPath());
$name = $md5 . '.' . $ext;
return $name;
}
示例8: uploadPhoto
/**
* @param UploadedFile $file
* @param Photo $photo
*/
public function uploadPhoto(UploadedFile $file, Photo &$photo)
{
$fileName = time() . '.' . $file->guessExtension();
$file->move($this->getUploadDir(), $fileName);
$photo->setName($fileName);
$photo->setOriginalName($file->getClientOriginalName());
}
示例9: upload
public static function upload(UploadedFile $file, $bucketName)
{
if (!$file->isValid()) {
throw new \Exception(trans('validation.invalid_file'));
}
$bucket = Bucket::find($bucketName);
if (!empty($bucket->mimeTypes()) && !in_array($file->getMimeType(), $bucket->mimeTypes())) {
throw new \Exception(trans('validation.invalid_file_type'));
}
if (!empty($bucket->maxSize()) && !in_array($file->getClientSize(), $bucket->maxSize())) {
throw new \Exception(trans('validation.invalid_file_size'));
}
$disk = Storage::disk($bucket->disk());
$media = Media::create(['mime' => $file->getMimeType(), 'bucket' => $bucketName, 'ext' => $file->guessExtension()]);
$disk->put($bucket->path() . '/original/' . $media->fileName, File::get($file));
if (is_array($bucket->resize())) {
foreach ($bucket->resize() as $name => $size) {
$temp = tempnam(storage_path('tmp'), 'tmp');
Image::make(File::get($file))->fit($size[0], $size[1])->save($temp);
$disk->put($bucket->path() . '/' . $name . '/' . $media->fileName, File::get($temp));
unlink($temp);
}
}
return $media;
}
示例10: preUpload
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if (null !== $this->file) {
$name = preg_replace('/([^a-z0-9\\-\\_])/i', '', $this->getName());
$this->setPath($this->getUploadDir() . '/' . $name . time() . '.' . $this->file->guessExtension());
}
}
示例11: upload
/**
* @param UploadedFile $uploadedFile
*/
function upload(UploadedFile $uploadedFile)
{
$path = sha1(uniqid(mt_rand(), true)) . '.' . $uploadedFile->guessExtension();
$this->setPath($path);
$this->setName($uploadedFile->getClientOriginalName());
$uploadedFile->move($this->getUploadRootDir(), $path);
}
示例12: moveUploadedFile
public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath)
{
$originalName = $file->getFilename() . '.' . $file->guessExtension();
$targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
$targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
$ext = $file->getExtension();
$i = 1;
while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
if ($ext) {
$prev = $i == 1 ? "" : $i;
$targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
} else {
$targetFilePath = $targetFilePath . $i++;
}
}
$targetDir = 'uploads';
if (!is_dir($targetDir)) {
$ret = mkdir($targetDir, 777, true);
if (!$ret) {
throw new \RuntimeException("Could not create target directory to move temporary file into.");
}
}
$file->move($targetDir, basename($targetFilePath));
return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
}
示例13: preUpload
public function preUpload()
{
if (null !== $this->file_domicile) {
// do whatever you want to generate a unique name
$this->path_domicile = uniqid() . '.' . $this->file_domicile->guessExtension();
}
if (null !== $this->file_prestations) {
// do whatever you want to generate a unique name
$this->path_prestations = uniqid() . '.' . $this->file_prestations->guessExtension();
}
if (null !== $this->file_salaire_1) {
// do whatever you want to generate a unique name
$this->path_salaire_1 = uniqid() . '.' . $this->file_salaire_1->guessExtension();
}
if (null !== $this->file_salaire_2) {
// do whatever you want to generate a unique name
$this->path_salaire_2 = uniqid() . '.' . $this->file_salaire_2->guessExtension();
}
if (null !== $this->file_salaire_3) {
// do whatever you want to generate a unique name
$this->path_salaire_3 = uniqid() . '.' . $this->file_salaire_3->guessExtension();
}
if (null !== $this->file_impots) {
// do whatever you want to generate a unique name
$this->path_impots = uniqid() . '.' . $this->file_impots->guessExtension();
}
}
示例14: preUpload
/**
* @ORM\PrePersist()
* @ORM\PreUpdate()
*/
public function preUpload()
{
if ($this->file === null) {
return;
}
$this->extension = $this->file->guessExtension();
$this->alt = $this->file->getClientOriginalName();
}
示例15: preUpload
public function preUpload()
{
if (null !== $this->file) {
$filename = sha1(uniqid(mt_rand(), true));
$this->path = $this->getUploadDir() . '/' . $filename . '.' . $this->file->guessExtension();
return $this->path;
}
}