PHP code example of dhananjay-vaidya / s3-connector
1. Go to this page and download the library: Download dhananjay-vaidya/s3-connector library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dhananjay-vaidya / s3-connector example snippets
'providers' => [
// ... other providers
DhananjayVaidya\S3Connector\S3ConnectorServiceProvider::class,
],
use DhananjayVaidya\S3Connector\S3ConnectorService;
class FileController extends Controller
{
protected $s3Service;
public function __construct(S3ConnectorService $s3Service)
{
$this->s3Service = $s3Service;
}
public function upload(Request $request)
{
$file = $request->file('file');
$result = $this->s3Service->upload($file, 'uploads/documents/');
if ($result['success']) {
return response()->json([
'message' => 'File uploaded successfully',
'data' => $result['data']
]);
}
return response()->json([
'error' => $result['error']
], 400);
}
}
use DhananjayVaidya\S3Connector\Facades\S3Connector;
// Upload a file
$result = S3Connector::upload($file, 'uploads/');
// Download a file
$result = S3Connector::download('uploads/file.pdf');
// List files
$files = S3Connector::list('uploads/', 100);
// Get file metadata
$metadata = S3Connector::metadata('uploads/file.pdf');