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.

34 lines
990 B

5 months ago
<?php
namespace App\Http\Controllers\Concerns;
20 hours ago
use App\Support\SecurePublicImageUpload;
5 months ago
use Illuminate\Http\UploadedFile;
/**
20 hours ago
* 公开图片上传统一走 SecurePublicImageUpload白名单后缀 + 魔数/MIME + UUID 文件名)。
5 months ago
*/
trait StoresPublicUploadWithoutFileinfo
{
20 hours ago
/**
* @return array{path: string, mime: string, extension: string}
*/
protected function storeUploadedFileAsUniqueName(UploadedFile $file, string $directory, int $maxKilobytes = 1024): array
5 months ago
{
20 hours ago
return SecurePublicImageUpload::store($file, $directory, $maxKilobytes);
5 months ago
}
protected function mimeForUploadResponse(UploadedFile $file): string
{
20 hours ago
$realPath = $file->getRealPath();
if (is_string($realPath) && is_readable($realPath)) {
$magic = SecurePublicImageUpload::mimeFromMagicBytes($realPath);
if ($magic !== null) {
return $magic;
5 months ago
}
}
20 hours ago
return 'application/octet-stream';
5 months ago
}
}