document.write('
  1. <?php
  2.  
  3. // Define the file path to your file
  4. // If you only define the filename, PHP will check on the current directory (relative path)
  5. // Else, you can define full path
  6. // Change to your file name
  7. $file_to_upload = \'yourimage.png\';
  8.  
  9. // S3 Bucket Name
  10. // Change to your bucket S3 bucket name
  11. $bucket = \'wordpressha\';
  12.  
  13. // S3 Endpoint
  14. // Change to your bucket S3 Endpoint URL
  15. $s3_endpoint = \'ap-southeast-mys1.oss.ips1cloud.com\';
  16.  
  17. // S3 Access and Secret Key
  18. // Change to your bucket S3 Access & Secret Key
  19. $access_key = \'5IRK7V7TVSV0B829WHAD\';
  20. $secret_key = \'I7BLtOZAsHdCDHMeyJ73QipBIPjLDCvWhIAzfynV\';
  21.  
  22. // Define your content type. Can leave as-is.
  23. $content_type = \'application/octet-stream\';
  24.  
  25. // Define date. Can leave as-is.
  26. $date_value = gmdate(\'D, d M Y H:i:s T\');
  27.  
  28. // Create the string to sign
  29. $string_to_sign = "PUT\\n\\n{$content_type}\\n{$date_value}\\n/{$bucket}/{$file_to_upload}";
  30.  
  31. // Create the signature
  32. $signature = base64_encode(hash_hmac(\'sha1\', $string_to_sign, $secret_key, true));
  33.  
  34. // Upload the file using curl
  35. $ch = curl_init();
  36. curl_setopt($ch, CURLOPT_URL, "https://{$bucket}.{$s3_endpoint}/{$file_to_upload}");
  37. curl_setopt($ch, CURLOPT_PUT, true);
  38. curl_setopt($ch, CURLOPT_INFILE, fopen($file_to_upload, \'r\'));
  39. curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file_to_upload));
  40. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  41.     "Host: {$bucket}.{$s3_endpoint}",
  42.     "Date: {$date_value}",
  43.     "Content-Type: {$content_type}",
  44.     "Authorization: AWS {$access_key}:{$signature}"
  45. ]);
  46. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  47.  
  48. $response = curl_exec($ch);
  49. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  50. curl_close($ch);
  51.  
  52. if ($http_code == 200) {
  53.     echo "File uploaded successfully.";
  54. } else {
  55.     echo "Failed to upload file. HTTP Status Code: {$http_code}";
  56. }
');