本文整理汇总了PHP中yii\web\UploadedFile::getBaseName方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getBaseName方法的具体用法?PHP UploadedFile::getBaseName怎么用?PHP UploadedFile::getBaseName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getBaseName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveData
/**
* @param \yii\web\UploadedFile $file
*
* @return int
*/
public function saveData(\yii\web\UploadedFile $file)
{
$ext = $file->getExtension();
$baseName = $file->getBaseName();
$model = new \metalguardian\fileProcessor\models\File();
$model->extension = $ext;
$model->base_name = $baseName;
$model->save(false);
return $model->id;
}
示例2: beforeSave
/**
* Before save event.
*
* @throws \yii\base\InvalidConfigException
*/
public function beforeSave()
{
if ($this->file instanceof UploadedFile) {
$this->_filePath = $this->resolvePath($this->filePath);
$owner = $this->owner;
$owner->{$this->attribute} = str_replace($this->_rootPath, '', $this->_filePath);
if ($this->filenameAttribute && empty($owner->{$this->filenameAttribute})) {
$owner->{$this->filenameAttribute} = $this->file->getBaseName();
}
}
}
示例3: createFromUploadedFile
public static function createFromUploadedFile(UploadedFile $file)
{
$upload = new static();
$upload->mimetype = FileHelper::getMimeType($file->tempName);
$upload->checksum = hash_file('sha256', $file->tempName);
$upload->filename = $file->getBaseName() . '.' . $file->getExtension();
$upload->filesize = $file->size;
$upload->createContainerDir();
$file->SaveAs($upload->getContainerDir() . '/' . $upload->filename);
$upload->save();
return $upload;
}
示例4: uploadPhoto
/**
* Загрузка изображения.
*
* @param UploadedFile $uploadedFile
* @param $userId
* @return bool
*/
public function uploadPhoto(UploadedFile $uploadedFile, $userId)
{
if ($uploadedFile->getBaseName() && !$uploadedFile->getHasError()) {
$photoName = 'profile_photo_' . $userId . '.' . $uploadedFile->getExtension();
$photoSaveFolder = \Yii::getAlias('@app') . $this->profilePhotoFolder . '/' . $userId;
if (!file_exists($photoSaveFolder)) {
mkdir($photoSaveFolder);
}
$photoPath = $photoSaveFolder . '/' . $photoName;
$uploadedFile->saveAs($photoPath);
return $photoName;
}
return false;
}
示例5: runForFile
/**
* @param UploadedFile $uploadedFile
*
* @return bool|string
*/
public function runForFile(UploadedFile $uploadedFile)
{
$extension = $uploadedFile->getExtension();
$baseName = $uploadedFile->getBaseName();
if ($this->useMd5Names) {
$filename = sprintf('%s', md5(time() . $baseName));
} elseif (is_null($this->customName) == false) {
$filename = sprintf("%s", $this->customName);
} else {
$filename = sprintf("%s", $baseName);
}
$filename = $this->getUniqueFilename($filename, $extension);
$filePath = $this->getFilePath($filename);
if ($uploadedFile->saveAs($filePath)) {
return $filename;
}
return false;
}
示例6: saveUploaded
protected function saveUploaded(UploadedFile $file)
{
$dir = $this->getPath(false, true);
$file_name = $file->getBaseName();
$file_ext = $file->getExtension();
$filename = $file_name . '.' . $file_ext;
$index = 0;
while (file_exists($dir . $filename)) {
$index++;
$filename = $file_name . '-' . $index . '.' . $file_ext;
}
FileHelper::createDirectory($dir, 0777, true);
$path = $dir . $filename;
if ($file->saveAs($path)) {
return [$filename, filesize($path)];
}
return false;
}
示例7: getFileName
/**
* @param UploadedFile $file
* @param callable $formatFileName
* @return string
*/
protected function getFileName(UploadedFile $file, \Closure $formatFileName = null)
{
$filename = $file->name;
if (!is_null($formatFileName)) {
$filename = call_user_func($formatFileName, $file->getBaseName(), $file->getExtension());
}
return $filename;
}
示例8: saveUploaded
protected function saveUploaded(UploadedFile $image)
{
$dir = $this->getPath(false, false, true);
$image_name = $image->getBaseName();
$image_ext = $image->getExtension();
$filename = $image_name . '.' . $image_ext;
$index = 0;
while (file_exists($dir . $filename)) {
$index++;
$filename = $image_name . '-' . $index . '.' . $image_ext;
}
$path = $dir . $filename;
$this->createFileDir($path);
if ($image->saveAs($path)) {
return $filename;
}
return false;
}