riftweb / storage
Laravel 包,简化存储服务。它提供了存储文件、检索路径、调整图片大小等方法。由 Leandro Santos 开发,使用 Spatie Image 库进行图片处理,与 PHP 7.3 和 8.0 兼容。
1.1.5
2024-03-06 21:43 UTC
Requires
- php: ^8.0
- spatie/image: ^3.3
Requires (Dev)
- orchestra/testbench: ^6.23|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.4|^10.1
README
Laravel 包,简化存储服务。它提供了存储文件、检索路径、调整图片大小等方法。由 Leandro Santos 开发,使用 Spatie Image 库进行图片处理,与 PHP 7.3 和 8.0 兼容。
关于我们
RIFT | Web Development 是一家软件开发公司,为企业提供定制解决方案。我们专注于网站和移动应用、电子商务和数字营销。我们的团队由对技术和创新充满热情的资深专业人士组成。我们致力于提供符合客户需求并超越客户期望的高质量产品。
安装
composer require riftweb/storage
使用方法
存储文件
use Riftweb\Storage\Classes\RiftStorage;
$file = $request->file('file');
$path = 'path/to/store';
$disk = 'public';
$shouldResize = true;
$width = 900;
$height = 900;
$storedFilePath = RiftStorage::store($file, $path, $disk, $shouldResize, $width, $height);
存储原始内容
use Riftweb\Storage\Classes\RiftStorage;
$content = 'Raw content';
$extension = 'txt';
$path = 'path/to/store';
$filename = 'file';
$disk = 'public';
$storedFilePath = RiftStorage::storeRaw($content, $extension, $path, $filename, $disk);
调整图片大小
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$width = 900;
$height = 900;
$storedFilePath = RiftStorage::resizeImage($path, $disk, $width, $height);
检查文件是否存在
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$exists = RiftStorage::exists($path, $disk);
删除文件
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$deleteSuccess = RiftStorage::delete($path, $disk);
下载文件
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$fileName = 'file';
$disk = 'public';
$response = RiftStorage::download($path, $fileName, $disk);
获取文件 URL
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$url = RiftStorage::getUrl($path, $disk);
获取文件临时 URL
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$expiration = 60;
$url = RiftStorage::getTemporaryUrl($path, $disk, $expiration);
获取文件大小
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$size = RiftStorage::getSize($path, $disk);
获取文件 MIME 类型
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$mime = RiftStorage::getMimeType($path, $disk);
获取文件扩展名
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$extension = RiftStorage::getExtension($path, $disk);
获取文件最后修改日期
use Riftweb\Storage\Classes\RiftStorage;
$path = 'path/to/file';
$disk = 'public';
$lastModified = RiftStorage::getLastModified($path, $disk);
许可证
RIFTweb Storage 包是开源软件,许可协议为 MIT 协议。