本文整理匯總了PHP中app\File::baseFile方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::baseFile方法的具體用法?PHP File::baseFile怎麽用?PHP File::baseFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\File
的用法示例。
在下文中一共展示了File::baseFile方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: saveTempFileByFileContent
public static function saveTempFileByFileContent($fileContent, User $user, $diskName = null)
{
$rootDir = "temp-file";
$fs = Storage::disk($diskName);
$md5 = md5($fileContent);
$sha1 = sha1($fileContent);
$size = strlen($fileContent);
$diskName = $diskName ? $diskName : Storage::getDefaultDriver();
$name = $md5 . '-' . $sha1;
$ext = '.tmp';
$now = Carbon::now();
$toDirPath = $rootDir . '/' . $now->year . '/' . $now->month . '/' . $now->day;
$toFilePath = $toDirPath . '/' . $md5 . '-' . $sha1 . '-' . str_random();
try {
$fs->makeDirectory($toDirPath);
} catch (\Exception $e) {
if (!$fs->exists($toDirPath)) {
throw $e;
}
}
if (!$fs->exists($toFilePath)) {
$fs->put($toFilePath, $fileContent);
}
$basicFile = new BasicFile();
$basicFile->md5 = $md5;
$basicFile->sha1 = $sha1;
$basicFile->size = $size;
$basicFile->disk = $diskName;
$basicFile->path = $toFilePath;
$fileModel = new FileModel();
$fileModel->name = $name;
$fileModel->ext = $ext;
$fileModel->mime = '';
$fileModel->user()->associate($user);
$fileModel->baseFile()->associate($basicFile);
return $fileModel;
}