本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::isValid方法的具体用法?PHP UploadedFile::isValid怎么用?PHP UploadedFile::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
}
}
示例2: upload
protected function upload(UploadedFile $file, $oldFile)
{
$list = "";
// foreach($files as $file)
// {
// $validator = Validator::make( array('file' => $file) , array('file' => array($this->Rule) ) );
//
// if($validator->fails())
// {
//laravel內建的驗證無法使用(可能是bug吧),所以自己寫一個
foreach ($this->Rule as $rule) {
if ($file->getClientOriginalExtension() == $rule) {
if ($file->isValid()) {
if ($this->groupno != "") {
$year = substr($this->groupno, 1, 3);
$destinationPath = public_path() . '/upload/' . $year . '/' . $this->groupno;
} else {
$destinationPath = public_path() . '/upload/teacher';
}
$fileName = $file->getClientOriginalName();
File::delete($destinationPath . '/' . $oldFile);
$file->move($destinationPath, $fileName);
//用 "|" 隔開檔名
$list .= $fileName . "|";
}
}
}
// }
// }
$list = substr($list, 0, -1);
return $list;
}
示例3: 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;
}
示例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 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;
}
示例6: putUploadedFile
/**
* Put and save a file in the public directory
*
* @param string path of the file
* @return mixed keypath of file or false if error occurred during uploading
*/
public static function putUploadedFile(UploadedFile $file)
{
if ($file->isValid()) {
//Remove all the slashes that doesn't serve
FileStorage::clearPublicStartPath();
//Retrive and save the file extension of the file uploaded
$fileExtension = $file->getClientOriginalExtension();
//Save the public path with the start path
$absolutePath = public_path() . '/' . FileStorage::$publicStartPath;
//Generate a random name to use for the file uploaded
$keyFile = FileStorage::generateKey(FileStorage::$keyLength) . '.' . $fileExtension;
//Check if the file with the $keyFile name doesn't exist, else, regenerate it
while (file_exists($absolutePath . '/' . ord($keyFile[0]) . '/' . $keyFile)) {
$keyFile = FileStorage::generateKey(FileStorage::$keyLength) . '.' . $fileExtension;
}
//Move the uploaded file and save
$file->move($absolutePath . '/' . ord($keyFile[0]), $keyFile);
//Save the keypath (start path, sub path, file name)
$keyPath = FileStorage::$publicStartPath . '/' . ord($keyFile[0]) . '/' . $keyFile;
//Return public path of the file
return $keyPath;
} else {
return false;
}
}
示例7: upload
public function upload(UploadedFile $file)
{
if ($file->isValid()) {
$name = $file->getClientOriginalName();
$size = $file->getClientSize();
}
}
示例8: doRequestUpload
/**
* Upload file from the request
*
* @param UploadedFile $file
* @return Array $data Retrieve into the content of response
* @throws BadRequestHttpException The file is too big
*/
private function doRequestUpload(UploadedFile $file)
{
$tmpDirectory = $this->getApplication()->getTemporaryDir();
$data = [];
if (null !== $file) {
if ($file->isValid()) {
if ($file->getClientSize() <= $file->getMaxFilesize()) {
$data = $this->buildData($file->getClientOriginalName(), $file->guessExtension());
$file->move($tmpDirectory, $data['filename']);
$data['size'] = round($file->getClientSize() / 1024, 2);
if ($imageInfo = @getimagesize($data['path'])) {
if (isset($imageInfo[0]) && isset($imageInfo[1])) {
$data['width'] = $imageInfo[0];
$data['height'] = $imageInfo[1];
}
} else {
$data['width'] = 0;
$data['height'] = 0;
}
} else {
throw new BadRequestHttpException('Too big file, the max file size is ' . $file->getMaxFilesize());
}
} else {
throw new BadRequestHttpException($file->getErrorMessage());
}
}
return $data;
}
示例9: 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);
}
示例10: init
/**
* @param UploadedFile $file
*
* @return Uploader
*
* @throws UploaderException
*/
public function init(UploadedFile $file)
{
// check if file correct
if (!$file->isValid()) {
throw new UploaderException($file->getErrorMessage());
}
$this->file = $file;
return $this;
}
示例11: uploadFile
public function uploadFile(UploadedFile $file, $fileName, $path)
{
try {
if ($file->isValid()) {
$file->move($path, $fileName);
}
} catch (\Exception $ex) {
throw $ex;
}
}
示例12: saveUploadedFile
/**
* Enregistre un fichier téléchargé en le déplaçant dans le répertoire $upload_directory sous le nom $filename.
* On conserve l'extension du fichier d'origine
*
* @param UploadedFile $file
* @param $uploadDirectory
* @param $filename
* @return bool
*/
public function saveUploadedFile(UploadedFile $file, $uploadDirectory, $filename)
{
if (!$file->isValid()) {
return false;
}
$this->upload_directory = $uploadDirectory;
$this->filename = $filename . '.' . $file->getClientOriginalExtension();
$file->move($this->upload_directory, $this->filename);
return true;
}
示例13: __construct
/**
* Constructor.
*
* @param Application $app
* @param string $formName
* @param File $file
*/
public function __construct(Application $app, $formName, UploadedFile $file)
{
$this->app = $app;
$this->formName = $formName;
$this->file = $file;
$this->fullPath = (string) $file;
$this->fileName = basename($this->fullPath);
$this->valid = $file->isValid();
$this->config = $app[Extension::CONTAINER]->config;
}
示例14: upload
/**
* Uploads the file
*
* @param UploadedFile $file
* @param $dir
*
* @return \WellCommerce\AppBundle\Entity\MediaInterface
* @throws \Exception
*/
public function upload(UploadedFile $file, $dir)
{
$uploadPath = $this->getUploadRootDir($dir);
if (!$file->isValid()) {
throw new \Exception('Passed file object is not valid');
}
$media = $this->createMediaFromUploadedFile($file);
$this->saveResource($media);
$file->move($uploadPath, $media->getPath());
return $media;
}
示例15: __construct
/**
* Constructor.
*
* @param Application $app
* @param string $formName
* @param File $file
*/
public function __construct(Application $app, $formName, UploadedFile $file)
{
$this->app = $app;
$this->formName = $formName;
$this->file = $file;
$this->fullPath = (string) $file;
$this->fileName = basename($this->fullPath);
$this->valid = $file->isValid();
$extension = $app['extensions']->get('Bolt/BoltForms');
$this->config = $extension->getConfig();
}