Step 1: Install Required Packages
sudo apt update
sudo apt install php php-cli php-zip unzip
sudo apt install php-xml
sudo mv composer.phar /usr/local/bin/composer
Make It Executable:
cd /path/to/your/project
composer init
composer require aws/aws-sdk-php
#############
<?phprequire 'vendor/autoload.php';
use Aws\S3\S3Client;use Aws\Exception\AwsException;
// Create a new S3 client$s3Client = new S3Client([ 'region' => 'us-east-1', // e.g. us-west-2 'version' => 'latest', 'credentials' => [ 'key' => 'AKMNB#888888PA', 'secret' => 'I54444444444444a' ],]);
$bucket = 'asteriskrecordings';$filePath = "$argv[1]"; // Local file path$keyName = basename($filePath); // Use the base name of the file
try { // Upload the file $result = $s3Client->putObject([ 'Bucket' => $bucket, 'Key' => $keyName, 'SourceFile' => $filePath ]);
echo "File uploaded successfully. File URL: " . $result['ObjectURL'] . "\n";} catch (AwsException $e) { // Output error message if upload fails echo "Error uploading file: " . $e->getMessage() . "\n";}?>