gpit/fileuploader
最新稳定版本:v0.03
Composer 安装命令:
composer require gpit/fileuploader
包简介
README 文档
README
Installation
You can install the package via Composer.
composer require gpit/fileuploader
Basic Usage Example
use gpit\fileuploader\FileUploader; use Illuminate\Http\Request; class ProfileController extends Controller { /** * Upload a profile image. * * @param \Illuminate\Http\Request $req * @return array */ public function profileImg(Request $req) { // Optional custom path $customPath = 'profile/images'; // Use FileUploader with the custom path $result = FileUploader::uploadFile($req, $customPath); if ($result[0]) { return ['success' => true, 'path' => $result['path']]; } else { return ['success' => false, 'error' => $result['error']]; } } }
Request Example
Example Request Payload:
{
"name": "avatar.png",
"file": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
Default Path
If no custom path is provided, the default upload path is files/. You can override this by passing a second argument to the uploadFile method:
$customPath = 'profile/images'; FileUploader::uploadFile($request, $customPath); // Files will be uploaded to 'profile/images/'
If you don't pass the custom path, files will be stored in the files/ directory by default:
FileUploader::uploadFile($request); // Files will be uploaded to 'files/'
Return Values
The uploadFile method returns an array with either the success status and path, or an error message in case of failure.
On Success:
[true, 'path' => 'profile/images/avatar.png']
On Failure:
[false, 'error' => 'Error message here']
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-09-05