本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getPathname方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getPathname方法的具体用法?PHP UploadedFile::getPathname怎么用?PHP UploadedFile::getPathname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getPathname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createTrackFromLocalHardDrive
/**
* Create track from local hard drive with job service
*
* @param MultimediaObject $multimediaObject
* @param UploadedFile $file
* @param string $profile
* @param int $priority
* @param string $language
* @param array $description
* @return MultimediaObject
*/
public function createTrackFromLocalHardDrive(MultimediaObject $multimediaObject, UploadedFile $trackFile, $profile, $priority, $language, $description)
{
if (null === $this->profileService->getProfile($profile)) {
throw new \Exception("Can't find given profile with name " . $profile);
}
if (UPLOAD_ERR_OK != $trackFile->getError()) {
throw new \Exception($trackFile->getErrorMessage());
}
if (!is_file($trackFile->getPathname())) {
throw new FileNotFoundException($trackFile->getPathname());
}
$pathFile = $trackFile->move($this->tmpPath . "/" . $multimediaObject->getId(), $trackFile->getClientOriginalName());
$this->jobService->addJob($pathFile, $profile, $priority, $multimediaObject, $language, $description);
return $multimediaObject;
}
示例2: upload
public function upload(UploadedFile $file, $filename, $headers = array())
{
$adapter = $this->filesystem->getAdapter();
$adapter->setMetadata($filename, $headers);
$adapter->write($filename, file_get_contents($file->getPathname()));
@unlink($file->getPathname());
return $filename;
}
示例3: store
/**
* Save file to folder.
*
* @author Casper Rasmussen <cr@nodes.dk>
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
* @param \Nodes\Assets\Upload\Settings $settings
*
* @return string
* @throws \Nodes\Assets\Upload\Exceptions\AssetsUploadFailedException
*/
protected function store(UploadedFile $uploadedFile, Settings $settings)
{
// Fallback folder is none is set
if (!$settings->hasFolder()) {
$settings->setFolder('default');
}
try {
// Retrieve folder path
$path = public_path(config('nodes.assets.providers.publicFolder.subFolder')) . DIRECTORY_SEPARATOR . $settings->getFolder();
// If folder doesn't exists,
// we'll create it with global permissions
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
// Stream uploaded file
$content = file_get_contents($uploadedFile->getPathname());
// Save uploaded file to folder
$result = file_put_contents($path . DIRECTORY_SEPARATOR . $settings->getFileName() . '.' . $settings->getFileExtension(), $content);
if (!$result) {
throw new NodesException('Failed to save', 500);
}
} catch (Exception $e) {
throw new AssetsUploadFailedException('Could not save the file to public folder. Reason: ' . $e->getMessage());
}
return $settings->getFilePath();
}
示例4: uploadFile
/**
* Upload provided file and create matching FileRecord object
*
* @param UploadedFile $file
* @param $clientIp
* @return FileRecord
*/
public function uploadFile(UploadedFile $file, $clientIp)
{
$extension = Str::lower($file->getClientOriginalExtension());
$generatedName = $this->generateName($extension);
// Create SHA-256 hash of file
$fileHash = hash_file('sha256', $file->getPathname());
// Check if file already exists
$existingFile = FileRecord::where('hash', '=', $fileHash)->first();
if ($existingFile) {
return $existingFile;
}
// Query previous scans in VirusTotal for this file
if (config('virustotal.enabled') === true) {
$this->checkVirusTotalForHash($fileHash);
}
// Get filesize
$filesize = $file->getSize();
// Check max upload size
$maxUploadSize = config('upload.max_size');
if ($filesize > $maxUploadSize) {
throw new MaxUploadSizeException();
}
// Move the file
$uploadDirectory = config('upload.directory');
$file->move($uploadDirectory, $generatedName);
// Create the record
/** @var FileRecord $record */
$record = FileRecord::create(['client_name' => $file->getClientOriginalName(), 'generated_name' => $generatedName, 'filesize' => $filesize, 'hash' => $fileHash, 'uploaded_by_ip' => $clientIp]);
return $record;
}
示例5: addPicFile
/**
* Set a pic from an url into the event
*/
public function addPicFile(Event $event, UploadedFile $picFile)
{
if (UPLOAD_ERR_OK != $picFile->getError()) {
throw new \Exception($picFile->getErrorMessage());
}
if (!is_file($picFile->getPathname())) {
throw new FileNotFoundException($picFile->getPathname());
}
$path = $picFile->move($this->targetPath . "/" . $event->getId(), $picFile->getClientOriginalName());
$pic = new Pic();
$pic->setUrl(str_replace($this->targetPath, $this->targetUrl, $path));
$pic->setPath($path);
$event->setPic($pic);
$this->dm->persist($event);
$this->dm->flush();
return $event;
}
示例6: store
/**
* @param UploadedFile $image
* @param string $visibility
* @return $this
*/
public function store(UploadedFile $image, $visibility = Filesystem::VISIBILITY_PUBLIC)
{
$info = getimagesize($image->getPathname());
$this->width = $info[0];
$this->height = $info[1];
$this->cloud->put($this->path, file_get_contents($image), $visibility);
return $this;
}
示例7: remove
/**
* Physically deletes the file
* @return bool
*/
public function remove()
{
if (file_exists($this->photoUpload->getPathname())) {
unlink($this->photoUpload->getPathname());
return true;
}
return false;
}
示例8: upload
public static function upload(UploadedFile $file, $user)
{
$userId = $user;
if ($user instanceof User) {
$userId = $user->id;
}
$hash = md5_file($file->getPathname());
$image = Image::whereHash($hash)->whereUploadedBy($userId)->first();
if ($image) {
return $image;
}
$image = new Image();
try {
$image->uploaded_by = $userId;
$image->size = $file->getSize();
$image->filename = $file->getClientOriginalName();
$image->extension = $file->getClientOriginalExtension();
$image->mime = $file->getMimeType();
$image->hash = $hash;
$image->save();
$image->ensureDirectoryExists();
foreach (self::$ImageTypes as $coverType) {
if ($coverType['id'] === self::ORIGINAL && $image->mime === 'image/jpeg') {
$command = 'cp ' . $file->getPathname() . ' ' . $image->getFile($coverType['id']);
} else {
// ImageMagick options reference: http://www.imagemagick.org/script/command-line-options.php
$command = 'convert 2>&1 "' . $file->getPathname() . '" -background white -alpha remove -alpha off -strip';
if ($image->mime === 'image/jpeg') {
$command .= ' -quality 100 -format jpeg';
} else {
$command .= ' -quality 95 -format png';
}
if (isset($coverType['width']) && isset($coverType['height'])) {
$command .= " -thumbnail {$coverType['width']}x{$coverType['height']}^ -gravity center -extent {$coverType['width']}x{$coverType['height']}";
}
$command .= ' "' . $image->getFile($coverType['id']) . '"';
}
External::execute($command);
chmod($image->getFile($coverType['id']), 0644);
}
return $image;
} catch (\Exception $e) {
$image->delete();
throw $e;
}
}
示例9: doUpload
/**
* {@inheritDoc}
*/
protected function doUpload(PropertyMapping $mapping, UploadedFile $file, $dir, $name)
{
$filesystem = $this->getFilesystem($mapping);
$path = !empty($dir) ? $dir . '/' . $name : $name;
if ($filesystem->getAdapter() instanceof MetadataSupporter) {
$filesystem->getAdapter()->setMetadata($path, array('contentType' => $file->getMimeType()));
}
$filesystem->write($path, file_get_contents($file->getPathname()), true);
}
示例10: addMaterialFile
/**
* Add a material from a file into the multimediaObject
*/
public function addMaterialFile(MultimediaObject $multimediaObject, UploadedFile $materialFile, $formData)
{
if (UPLOAD_ERR_OK != $materialFile->getError()) {
throw new \Exception($materialFile->getErrorMessage());
}
if (!is_file($materialFile->getPathname())) {
throw new FileNotFoundException($materialFile->getPathname());
}
$material = new Material();
$material = $this->saveFormData($material, $formData);
$path = $materialFile->move($this->targetPath . "/" . $multimediaObject->getId(), $materialFile->getClientOriginalName());
$material->setPath($path);
$material->setUrl(str_replace($this->targetPath, $this->targetUrl, $path));
$multimediaObject->addMaterial($material);
$this->dm->persist($multimediaObject);
$this->dm->flush();
return $multimediaObject;
}
示例11: upload
public function upload(UploadedFile $file)
{
if (!in_array($file->getMimeType(), $this->allowedMimeTypes)) {
throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getMimeType()));
}
$filename = sprintf('%s/%s/%s/%s.%s', date('Y'), date('m'), date('d'), uniqid(), $file->getClientOriginalExtension());
$adapter = $this->filesystem->getAdapter();
$adapter->setMetadata($filename, array('contentType' => $file->getMimeType()));
$adapter->write($filename, file_get_contents($file->getPathname()));
return $adapter->getUrl($filename);
}
示例12: upload
public function upload(UploadedFile $file, $path)
{
// Check if the file's mime type is in the list of allowed mime types.
if (!in_array($file->getClientMimeType(), self::$allowedMimeTypes)) {
throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getClientMimeType()));
}
$adapter = $this->filesystem->getAdapter();
$adapter->setMetadata($path, array('contentType' => $file->getClientMimeType()));
$adapter->write($path, file_get_contents($file->getPathname()));
return $path;
}
示例13: putUploadedFile
/**
* @param UploadedFile $uploadedFile
* @param FileEntity $fileEntity
* @return bool
*/
public function putUploadedFile(UploadedFile $uploadedFile, FileEntity $fileEntity)
{
list($path, $filesystem, $settings) = $this->getConfigValuesForRecordType($fileEntity->getRecordType());
$fullPath = $path . DIRECTORY_SEPARATOR . $fileEntity->getFileName();
$this->getFilesystem($filesystem)->putStream($fullPath, fopen($uploadedFile->getPathname(), 'r'), $settings);
$fileEntity->setContentType($uploadedFile->getMimeType())->setSize($uploadedFile->getSize());
/** @var EntityManager $em */
$em = $this->container['orm.em'];
$em->flush();
return $fileEntity;
}
示例14: uploadFile
protected function uploadFile(UploadedFile $file)
{
$web_path = '/uploads/fc_request/' . date('Y/m/d');
$directory = rtrim(__DIR__, '/') . '/../../../../../../../../../web' . $web_path;
$name = $file->getClientOriginalName();
@mkdir($directory, 0777, true);
if (!@copy($file->getPathname(), $directory . '/' . $name)) {
return null;
}
return $web_path . '/' . $name;
}
示例15: resizeAndSave
/**
* Resize user avatar from uploaded picture
* @param \Symfony\Component\HttpFoundation\File\UploadedFile|\Symfony\Component\HttpFoundation\File\File $original
* @param int $user_id
* @param string $size
* @throws \Exception
* @return null
*/
public function resizeAndSave($original, $user_id, $size = 'small')
{
$sizeConvert = ['big' => [400, 400], 'medium' => [200, 200], 'small' => [100, 100]];
if (!array_key_exists($size, $sizeConvert)) {
return null;
}
$image = new Image();
$image->setCacheDir(root . '/Private/Cache/images');
$image->open($original->getPathname())->cropResize($sizeConvert[$size][0], $sizeConvert[$size][1])->save(root . '/upload/user/avatar/' . $size . '/' . $user_id . '.jpg', 'jpg', static::COMPRESS_QUALITY);
return null;
}