You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Concerns;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Support\SecurePublicImageUpload;
|
|
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 公开图片上传统一走 SecurePublicImageUpload(白名单后缀 + 魔数/MIME + UUID 文件名)。
|
|
|
|
|
|
*/
|
|
|
|
|
|
trait StoresPublicUploadWithoutFileinfo
|
|
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @return array{path: string, mime: string, extension: string}
|
|
|
|
|
|
*/
|
|
|
|
|
|
protected function storeUploadedFileAsUniqueName(UploadedFile $file, string $directory, int $maxKilobytes = 1024): array
|
|
|
|
|
|
{
|
|
|
|
|
|
return SecurePublicImageUpload::store($file, $directory, $maxKilobytes);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected function mimeForUploadResponse(UploadedFile $file): string
|
|
|
|
|
|
{
|
|
|
|
|
|
$realPath = $file->getRealPath();
|
|
|
|
|
|
if (is_string($realPath) && is_readable($realPath)) {
|
|
|
|
|
|
$magic = SecurePublicImageUpload::mimeFromMagicBytes($realPath);
|
|
|
|
|
|
if ($magic !== null) {
|
|
|
|
|
|
return $magic;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 'application/octet-stream';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|