gpit / fileuploader
There is no license information available for the latest version (v0.03) of this package.
v0.03
2024-09-06 08:37 UTC
Requires
- php: ^8.0
- illuminate/support: ^11.22
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']