本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getClientSize方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getClientSize方法的具体用法?PHP UploadedFile::getClientSize怎么用?PHP UploadedFile::getClientSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getClientSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* Upload new attachment
*
* @param UploadedFile $file
* @param string $descriptionText
* @param Language $language
* @param array $attributes
* @param Attachment $attachment
*
* @return Attachment
*/
public function upload(UploadedFile $file, $descriptionText, Language $language, array $attributes, Attachment $attachment = null)
{
$filesystem = new Filesystem();
$filesize = $file->getClientSize();
if ($filesize == false) {
throw new FileException('File size is not valid');
}
if (!file_exists($this->config['file_directory']) || !is_writable($this->config['file_directory'])) {
throw new FileException('Directory ' . $this->config['file_directory'] . ' is not writable');
}
if (!is_null($attachment)) {
if ($filesystem->exists($this->getStorageLocation($attachment))) {
$filesystem->remove($this->getStorageLocation($attachment));
}
if ($descriptionText != $attachment->getDescription()->getTranslationText()) {
$nextTranslationPhraseId = $this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextTranslationPhraseId();
$description = new Translation($nextTranslationPhraseId);
$description->setLanguage($language);
$description->setTranslationText($descriptionText);
$this->em->persist($description);
}
unset($attributes['description']);
} else {
$attachment = new Attachment();
$nextTranslationPhraseId = $this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextTranslationPhraseId();
$description = new Translation($nextTranslationPhraseId);
$description->setLanguage($language);
$description->setTranslationText($descriptionText);
unset($attributes['description']);
$attachment->setCreated(new \DateTime());
$this->em->persist($description);
$this->em->persist($attachment);
}
$attributes = array_merge(array('language' => $language, 'name' => $file->getClientOriginalName(), 'extension' => $file->getClientOriginalExtension(), 'mimeType' => $file->getClientMimeType(), 'contentDisposition' => Attachment::CONTENT_DISPOSITION, 'sizeInBytes' => $file->getClientSize(), 'description' => $description), $attributes);
$this->fillAttachment($attachment, $attributes);
if (is_null($attributes['name'])) {
$attachment->setName($file->getClientOriginalName());
}
$this->em->flush();
$target = $this->makeDirectories($attachment);
try {
$file->move($target, $this->getFileName($attachment));
$filesystem->chmod($target . '/' . $this->getFileName($attachment), 0644);
} catch (\Exceptiom $e) {
$filesystem->remove($target);
$this->em->remove($attachment);
$this->em->flush();
throw new \Exception($e->getMessage(), $e->getCode());
}
return $attachment;
}
示例2: handle
/**
* Handle the file upload. Returns the array on success, or false
* on failure.
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
* @param String $path where to upload file
* @return array|bool
*/
public function handle(UploadedFile $file, $path = 'uploads')
{
$input = array();
$fileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
// Detect and transform Croppa pattern to avoid problem with Croppa::delete()
$fileName = preg_replace('#([0-9_]+)x([0-9_]+)#', "\$1-\$2", $fileName);
$input['path'] = $path;
$input['extension'] = '.' . $file->getClientOriginalExtension();
$input['filesize'] = $file->getClientSize();
$input['mimetype'] = $file->getClientMimeType();
$input['filename'] = $fileName . $input['extension'];
$fileTypes = Config::get('file.types');
$input['type'] = $fileTypes[strtolower($file->getClientOriginalExtension())];
$filecounter = 1;
while (file_exists($input['path'] . '/' . $input['filename'])) {
$input['filename'] = $fileName . '_' . $filecounter++ . $input['extension'];
}
try {
$file->move($input['path'], $input['filename']);
list($input['width'], $input['height']) = getimagesize($input['path'] . '/' . $input['filename']);
return $input;
} catch (FileException $e) {
Notification::error($e->getmessage());
return false;
}
}
示例3: 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;
}
示例4: isFileUpload
/**
* @param string|array|UploadedFile $data
*
* @return bool
*/
protected function isFileUpload($data)
{
if ($data instanceof UploadedFile) {
return $data->isValid() && $data->getClientSize() > 0;
}
return is_array($data) && !empty($data['tmp_name']) && !empty($data['size']) && $data['error'] === UPLOAD_ERR_OK;
}
示例5: upload
public function upload(UploadedFile $file)
{
if ($file->isValid()) {
$name = $file->getClientOriginalName();
$size = $file->getClientSize();
}
}
示例6: 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;
}
示例7: validSize
/**
* @param UploadedFile $file
* @return bool
*/
protected function validSize(UploadedFile $file)
{
$size = $file->getClientSize();
if ($size > self::MAX_FILE_SIZE) {
return false;
}
return true;
}
示例8: createMediaFromUploadedFile
/**
* @param UploadedFile $file
*
* @return \WellCommerce\Bundle\MediaBundle\Entity\MediaInterface
*/
protected function createMediaFromUploadedFile(UploadedFile $file)
{
$media = $this->initResource();
$media->setName($file->getClientOriginalName());
$media->setExtension($file->guessClientExtension());
$media->setMime($file->getClientMimeType());
$media->setSize($file->getClientSize());
return $media;
}
示例9: setFile
public function setFile(\Symfony\Component\HttpFoundation\File\UploadedFile $file)
{
// temporarily save file for further handling
$this->tempFile = $file;
$this->filename = $file->getClientOriginalName();
$this->size = $file->getClientSize();
$this->extension = $file->getClientOriginalExtension();
$this->mimetype = $file->getMimeType();
}
示例10: ucwords
/**
* @param UploadedFile $uploadedFile
*/
function __construct(UploadedFile $uploadedFile)
{
$cleanFilename = preg_replace("/[^A-Za-z0-9\\.]/", "-", ucwords(strtolower($uploadedFile->getClientOriginalName())));
$path = uniqid() . '-' . $cleanFilename;
$this->setPath($path);
$this->setSize($uploadedFile->getClientSize());
$this->setName($cleanFilename);
$uploadedFile->move($this->getUploadRootDir(), $path);
}
示例11: fromPost
/**
* Creates a file object from a file an uploaded file.
* @param Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
*/
public function fromPost($uploadedFile)
{
if ($uploadedFile === null) {
return;
}
$this->file_name = $uploadedFile->getClientOriginalName();
$this->file_size = $uploadedFile->getClientSize();
$this->content_type = $uploadedFile->getMimeType();
$this->disk_name = $this->getDiskName();
$this->putFile($uploadedFile->getRealPath(), $this->disk_name);
}
示例12: save
/**
* {@inheritdoc}
*/
public function save(UploadedFile $file, $dir)
{
$media = new Media();
$media->setName($file->getClientOriginalName());
$media->setExtension($file->guessClientExtension());
$media->setMime($file->getClientMimeType());
$media->setSize($file->getClientSize());
$this->_em->persist($media);
$this->_em->flush();
return $media;
}
示例13: createUpload
/**
* @param UserModel $user
* @param UploadedFile $file
* @param ImageTypeModel $image_type
*
* @throws InvalidCreationException
* @return ImageModel
*/
public function createUpload($owner, $file, $uploadTarget, $uploadInfo)
{
// Check that image is valid
$ext = $file->guessClientExtension();
if ($ext == "jpeg") {
$ext = "jpg";
}
$size = $file->getClientSize();
if (!in_array($ext, $this->valid_exts)) {
throw new InvalidCreationException('File format unacceptable: ' . $ext);
}
if (!$size || $size > $this->max_size) {
throw new InvalidCreationException('File is too large: ' . strval($size));
}
if ($uploadInfo['unique'] == true) {
try {
$target = \DB::table('upload_map')->where('owner_hash', $uploadTarget->hash)->where('upload_type', $uploadInfo['type'])->first();
if ($target) {
$previousUpload = $this->uploadRepository->getByUploadWithTypeAndTarget($uploadTarget, $uploadInfo['type'])->first();
$this->deleteUpload($previousUpload);
\DB::table('upload_map')->where('upload_hash', $previousUpload->hash)->delete();
}
} catch (ModelNotFoundException $e) {
//To be expected if there is no previous
}
}
$upload_dir = storage_path() . '/app/' . $owner->hash;
// Create the path for the upload file
if (!\File::exists($upload_dir)) {
\File::makeDirectory($upload_dir, 0775);
}
// Create data for object
$data = [];
$data['user_id'] = $owner->id;
$data['extension'] = $ext;
$data['upload_type'] = $uploadInfo['type'];
$data['path'] = $upload_dir;
// Create the object
// Create the full image
if ($ext != 'pdf') {
\Cloudder::upload($file);
$publicID = \Cloudder::getPublicId();
} else {
\Cloudder::upload($file);
$publicID = \Cloudder::getPublicId();
}
$data['hash'] = $publicID;
$upload = $this->uploadRepository->create($data);
\DB::table('upload_map')->insert(['upload_hash' => $publicID, 'owner_hash' => $uploadTarget->hash, 'upload_type' => $uploadInfo['type'], 'created_at' => date('Y-m-d G:i:s'), 'updated_at' => date('Y-m-d G:i:s')]);
\Log::info('New upload created', $upload->toArray());
return $upload;
}
示例14: createFromObject
/**
* Build a \Torann\MediaSort\File\UploadedFile object from
* a Symfony\Component\HttpFoundation\File\UploadedFile object.
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
*
* @return \Torann\MediaSort\File\UploadedFile
* @throws \Torann\MediaSort\Exceptions\FileException
*/
protected function createFromObject(SymfonyUploadedFile $file)
{
$path = $file->getPathname();
$originalName = $file->getClientOriginalName();
$mimeType = $file->getClientMimeType();
$size = $file->getClientSize();
$error = $file->getError();
$uploadFile = new UploadedFile($path, $originalName, $mimeType, $size, $error);
if (!$uploadFile->isValid()) {
throw new FileException($uploadFile->getErrorMessage($uploadFile->getError()));
}
return $uploadFile;
}
示例15: checkFile
protected function checkFile(UploadedFile $file)
{
$mime = $file->getClientMimeType();
$info = array('name' => $file->getClientOriginalName(), 'size' => $file->getClientSize(), 'mime' => $mime, 'extension' => $file->getClientOriginalExtension(), 'type' => $mime, 'error' => '');
if ($file->isValid()) {
if (!$info['type']) {
$info['status'] = 9;
$info['error'] = '不支持的文件类型';
} else {
$info['status'] = UPLOAD_ERR_OK;
}
} else {
$info['status'] = $file->getError();
$info['error'] = $file->getErrorMessage();
}
return $info;
}