stew/image-uploader
Composer 安装命令:
composer require stew/image-uploader
包简介
Image uploads using Laravel Storage and conversion to format .webp
README 文档
README
Installation
composer require stew/image-uploader
Usage
- Step 1: Import the UploaderTrait
use Stew\ImageUploader\Traits\UploaderTrait;
- Step 2: Implement the Trait in Your Class/Controller
use Stew\ImageUploader\Traits\UploaderTrait;
class YourController extends Controller
{
use UploaderTrait;
public function uploadImage(Request $request)
{
// code
}
}
Utilize the Provided Methods
Get Image Disk
- The getImageDisk() method retrieves the name of the image storage disk. By default, it reads the FILESYSTEM_DISK environment variable. You can specify a different disk by setting the FILESYSTEM_DISK variable in your environment configuration.
$this->getImageDisk();
- Make sure that your
.envfile and configfilesystems.defaulthas the FILESYSTEM_DISK variable, for example:
FILESYSTEM_DISK=local
'default' => env('FILESYSTEM_DISK', 'local'),
- To use the database for storing configuration, you need to run a migration with the following command:
php artisan migrate
- The above command will create a "settings" table with the following structure:
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->text('value');
$table->timestamps();
});
- We have provided sample data for you to test. You can seed the sample data with the following command.
php artisan db:seed --class=Stew\\ImageUploader\\Database\\Seeders\\SettingSeeder
- To use configuration from the "settings" table (by default), you can use the following function:
$this->getImageDisk('YOUR TABLE') // Default is "settings"
- If you want to customize the seeded data, you can use the following command:
php artisan vendor:publish --provider="Stew\ImageUploader\Providers\ImageUploaderServiceProvider"
Get Storage Directory
- To obtain the storage directory for images, use the getDirectory($path) method.
$this->getDirectory($path);
Save Image File to Storage
- This method is used to save an image file to your storage. It returns a string representing the path to the saved image with a .webp extension.
$this->saveFileToStorage($fileName, $path);
Check for Base64 String
- To check if a string is a base64 string, use the isBase64($strEndcode) method.
$this->isBase64($strEndcode);
Delete Image
- To delete an image file from storage, utilize the deleteImage($filePath) method.
$this->deleteImage($filePath);
The Public Disk
- To create the symbolic link, you may use the storage:link Artisan command:
php artisan storage:link
stew/image-uploader 适用场景与选型建议
stew/image-uploader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 stew/image-uploader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stew/image-uploader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-10-19