本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::move方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::move方法的具体用法?PHP UploadedFile::move怎么用?PHP UploadedFile::move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::move方法的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: 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));
}
示例3: save
/**
* {@inheritdoc}
*/
public function save()
{
if (null !== $this->file) {
$this->file->move($this->getUploadRootDir(), $this->path);
unset($this->file);
}
return $this;
}
示例4: upload
public function upload()
{
if (null === $this->file) {
return;
}
$name = $this->file->getClientOriginalName();
$this->file->move($this->getUploadRootDir(), $name);
$this->url = $name;
}
示例5: save
/**
* Process the form.
*
* @return void
*/
public function save()
{
// attach the photo to the flyer
$photo = $this->flyer->addPhoto($this->makePhoto());
// move the photo to the image folder
$this->file->move($photo->baseDir(), $photo->name);
// generate a thumbnail
$this->thumbnail->make($photo->path, $photo->thumbnail_path);
}
示例6: uploadAvatar
/**
* Uplaod a photo if exits.
*/
protected function uploadAvatar()
{
if (!$this->file) {
return;
}
$name = $this->makeFileName();
$this->user['avatar'] = '/' . $this->baseDir . $name;
$this->file->move($this->baseDir, $name);
$this->fitAvatar($this->user['avatar']);
}
示例7: upload
public function upload()
{
if ($this->rules->passes()) {
try {
$this->file->move($this->path . $this->subfolder, $this->filename . '.' . $this->file->getClientOriginalExtension());
return true;
} catch (\Exception $e) {
dd($e->getMessage());
return false;
}
}
return false;
}
示例8: handle
/**
* @param Filesystem $files
* @param AccountManager $manager
* @return mixed
*/
public function handle(Filesystem $files, AccountManager $manager)
{
$temp_dir = storage_path('media') . '/' . $this->owner->getMediaFolder('images');
$name = $this->uniqueName();
$this->image->move($temp_dir, $name);
$temp_file = $temp_dir . $name;
$name_with_extension = $name . $this->extension($temp_file);
$final_path = $temp_file . $name_with_extension;
$files->move($temp_file, $final_path);
$image = $this->dispatch(new StoreNewImage($manager->account(), $this->owner, $final_path));
$files->delete($final_path);
return $image;
}
示例9: upload
/**
* @ORM\PostPersist()
* @ORM\PostUpdate()
*/
public function upload()
{
if (null === $this->file) {
return;
}
if (null !== $this->tempFilename) {
$oldFile = $this->getUploadRootDir() . '/' . $this->id . '.' . $this->tempFilename;
if (file_exists($oldFile)) {
unlink($oldFile);
}
}
$this->file->move($this->getUploadRootDir(), $this->id . '.' . $this->getUrl());
}
示例10: save
/**
* Save the file to the fileable type and id
*/
public function save()
{
$file = $this->makeFileRecord();
// move the file and add the size to the file model
$this->file->move($file->getSystemPath(), $file->filename);
if (\File::exists($file->getSystemPath() . $file->filename)) {
$file->filesize = \File::size($file->getSystemPath() . $file->filename);
}
if ($this->thumbnail->isPhoto($file->getSystemPath() . $file->filename)) {
$this->thumbnail->make($file);
}
$file->save();
}
示例11: 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);
}
}
}
示例12: moveUploadedFile
public function moveUploadedFile(UploadedFile $file, $uploadBasePath, $relativePath, $fileName)
{
$originalName = $file->getFilename();
// use filemtime() to have a more determenistic way to determine the subpath, otherwise its hard to test.
// $relativePath = date('Y-m', filemtime($file->getPath()));
$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 = $uploadBasePath . DIRECTORY_SEPARATOR . $relativePath;
if (!is_dir($targetDir)) {
$ret = mkdir($targetDir, umask(), true);
if (!$ret) {
throw new \RuntimeException("Could not create target directory to move temporary file into.");
}
}
//$file->move($targetDir, basename($targetFilePath));
//$file->move($targetDir, basename($fileName.'.'.$ext));
$file->move($targetDir, basename($fileName));
return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
}
示例13: upload
public function upload(UploadedFile $file, $folder)
{
$path = $this->path . $folder . '/';
$name = md5(uniqid(rand(), 1)) . '.' . $file->getClientOriginalExtension();
$file->move($path, $name);
return url('img', [$folder, $name]);
}
示例14: __construct
/**
* Constructor
*
* @param UploadedFileBase $uploadedFile
* @param CKFinder $app
*
* @throws \Exception if file upload failed
*/
public function __construct(UploadedFileBase $uploadedFile, CKFinder $app)
{
parent::__construct($uploadedFile->getClientOriginalName(), $app);
$this->uploadedFile = $uploadedFile;
$this->workingFolder = $app['working_folder'];
$this->tempFilePath = tempnam($this->config->get('tempDirectory'), 'ckf');
$pathinfo = pathinfo($this->tempFilePath);
if (!is_writable($this->tempFilePath)) {
throw new InvalidUploadException('The temporary folder is not writable for CKFinder');
}
try {
$uploadedFile->move($pathinfo['dirname'], $pathinfo['basename']);
} catch (\Exception $e) {
$errorMessage = $uploadedFile->getErrorMessage();
switch ($uploadedFile->getError()) {
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new InvalidUploadException($errorMessage, Error::UPLOADED_TOO_BIG, array(), $e);
case UPLOAD_ERR_PARTIAL:
case UPLOAD_ERR_NO_FILE:
throw new InvalidUploadException($errorMessage, Error::UPLOADED_CORRUPT, array(), $e);
case UPLOAD_ERR_NO_TMP_DIR:
throw new InvalidUploadException($errorMessage, Error::UPLOADED_NO_TMP_DIR, array(), $e);
case UPLOAD_ERR_CANT_WRITE:
case UPLOAD_ERR_EXTENSION:
throw new AccessDeniedException($errorMessage, array(), $e);
}
}
}
示例15: saveUserUploadedPhoto
public function saveUserUploadedPhoto(UploadedFile $file)
{
$extension = CommonFunction::getFileExtension($file->getClientOriginalName());
$fileName = md5(microtime(true)) . '.' . $extension;
$file->move($this->getUserPhotoDir(), $fileName);
return $fileName;
}