<?php
// Define the file path to your file
// If you only define the filename, PHP will check on the current directory (relative path)
// Else, you can define full path
// Change to your file name
$file_to_upload = \'yourimage.png\';
// S3 Bucket Name
// Change to your bucket S3 bucket name
$bucket = \'wordpressha\';
// S3 Endpoint
// Change to your bucket S3 Endpoint URL
$s3_endpoint = \'ap-southeast-mys1.oss.ips1cloud.com\';
// S3 Access and Secret Key
// Change to your bucket S3 Access & Secret Key
$access_key = \'5IRK7V7TVSV0B829WHAD\';
$secret_key = \'I7BLtOZAsHdCDHMeyJ73QipBIPjLDCvWhIAzfynV\';
// Define your content type. Can leave as-is.
$content_type = \'application/octet-stream\';
// Define date. Can leave as-is.
$date_value = gmdate(\'D, d M Y H:i:s T\');
// Create the string to sign
$string_to_sign = "PUT\\n\\n{$content_type}\\n{$date_value}\\n/{$bucket}/{$file_to_upload}";
// Create the signature
$signature = base64_encode(hash_hmac(\'sha1\', $string_to_sign, $secret_key, true));
// Upload the file using curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://{$bucket}.{$s3_endpoint}/{$file_to_upload}");
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, fopen($file_to_upload, \'r\'));
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_to_upload));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Host: {$bucket}.{$s3_endpoint}",
"Date: {$date_value}",
"Content-Type: {$content_type}",
"Authorization: AWS {$access_key}:{$signature}"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code == 200) {
echo "File uploaded successfully.";
} else {
echo "Failed to upload file. HTTP Status Code: {$http_code}";
}