本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getClientOriginalExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getClientOriginalExtension方法的具体用法?PHP UploadedFile::getClientOriginalExtension怎么用?PHP UploadedFile::getClientOriginalExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\File\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getClientOriginalExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makePath
/**
* Makes a fully qualifies image path with either
* random name or original name.
*
* @param Upload $image
* @param boolean $useOriginal
* @return string
*/
public function makePath(Upload $image, $useOriginal)
{
$base = public_path('assets/uploads/images/');
if ($useOriginal) {
return $base . $image->getClientOriginalName() . '.' . $image->getClientOriginalExtension();
}
return $base . str_random(10) . '.' . $image->getClientOriginalExtension();
}
示例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: fileName
/**
* Get the file name for the photo
*
* @return string
*/
public function fileName()
{
if (!is_null($this->name) && $this->name) {
return $this->name;
}
$name = sha1($this->file->getClientOriginalName() . '-' . microtime());
$extension = $this->file->getClientOriginalExtension();
return "{$name}.{$extension}";
}
示例4: upload
public static function upload(UploadedFile $file, $uploadPath = null)
{
if (is_null($uploadPath)) {
$uploadPath = public_path() . '/uploads/';
}
$fileName = str_slug(getFileName($file->getClientOriginalName())) . '.' . $file->getClientOriginalExtension();
//Make file name unique so it doesn't overwrite any old photos
while (file_exists($uploadPath . $fileName)) {
$fileName = str_slug(getFileName($file->getClientOriginalName())) . '-' . str_random(5) . '.' . $file->getClientOriginalExtension();
}
$file->move($uploadPath, $fileName);
return ['filename' => $fileName, 'fullpath' => $uploadPath . $fileName];
}
示例5: 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;
}
示例6: uploadFile
/**
* 上传单个文件
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
* @param bool $autoName
* @return null|string
*/
public function uploadFile(UploadedFile $file, $autoName = true)
{
//print_r($file);exit;
if ($autoName) {
$filename = sprintf('%s.%s', uniqid(), $file->getClientOriginalExtension());
} else {
$filename = $file->getClientOriginalName();
}
$relativePath = '';
switch ($this->groupedBy) {
case static::GROUPED_BY_MONTH:
$dateObj = new \DateTime();
$relativePath = $dateObj->format('Y-m') . '/';
break;
case static::GROUPED_BY_DATE:
$dateObj = new \DateTime();
$relativePath = $dateObj->format('Y-m') . '/' . $dateObj->format('d') . '/';
break;
default:
}
$toDir = $this->getUploadDir() . $relativePath;
if (!$this->fs->exists($toDir)) {
$this->fs->mkdir($toDir);
}
$file->move($toDir, $filename);
return $relativePath . $filename;
}
示例7: getFilename
/**
* Generate a proper filename.
*
* @param UploadedFile $file
* @return bool|string
*/
private function getFilename(UploadedFile $file)
{
$path = $file->getClientOriginalName();
$path .= '_' . dechex(time());
$path .= '.' . $file->getClientOriginalExtension();
return $path;
}
示例8: upload
public function upload(UploadedFile $file, $path = null)
{
// 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()));
}
if ($path) {
$filename = sprintf('%s/%s.%s', $path, md5(time() * rand(0, 99)), $file->getClientOriginalExtension());
} else {
$filename = sprintf('%s/%s/%s/%s.%s', date('Y'), date('m'), date('d'), md5(time() * rand(0, 99)), $file->getClientOriginalExtension());
}
$adapter = $this->filesystem->getAdapter();
$adapter->setMetadata($filename, array('contentType' => $file->getClientMimeType()));
$adapter->write($filename, file_get_contents($file->getPathname()));
return $filename;
}
示例9: 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]);
}
示例10: parseUserFile
/**
* Converts UploadedFile of users into array of User objects
*
* @param UploadedFile $file
* @return array
*/
public function parseUserFile(UploadedFile $file)
{
$data = array('users' => array(), 'columns' => array());
switch ($file->getClientOriginalExtension()) {
case 'csv':
$file = $file->openFile();
$data['columns'] = $file->fgetcsv();
while (!$file->eof()) {
$user = new User();
$row = $file->fgetcsv();
if (array(null) == $row) {
continue;
}
foreach ($row as $key => $userProperty) {
$functionName = 'set' . ucfirst($data['columns'][$key]);
if (!method_exists($user, $functionName)) {
throw new MappingException('User has no property ' . $data['columns'][$key]);
}
$user->{$functionName}($userProperty);
}
$this->isUserValid($user);
$data['users'][] = $user;
}
break;
}
return $data;
}
示例11: 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;
}
}
示例12: canUpload
/**
* {@inheritdoc}
*/
public function canUpload(UploadedFile $file)
{
if ($file->getMimeType() == 'text/plain' && $file->getClientOriginalExtension() == 'md') {
return 5;
}
return 0;
}
示例13: 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;
}
示例14: uploadSingleFile
/**
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
*
* @return string
*/
protected function uploadSingleFile($file)
{
$filename = uniqid() . '.' . $file->getClientOriginalExtension();
$targetDirectory = public_path($this->config->get('paxifi.files.uploads_directory'));
$file->move($targetDirectory, $filename);
return $this->config->get('app.url') . '/' . basename($targetDirectory) . '/' . $filename;
}
示例15: generateFilename
/**
* @param \Symfony\Component\HttpFoundation\File\UploadedFile|array $file
*
* @return string
*/
public static function generateFilename($file)
{
$filename = md5(uniqid() . '_' . $file->getClientOriginalName());
$extension = $file->getClientOriginalExtension();
$filename = $extension ? $filename . '.' . $extension : $filename;
return $filename;
}