Configure PowerCMS inline editor to upload images to Amazon S3 storage
I've got a function that I use already when posting a form to upload files to my amazon s3 storage, but I was hoping to be able to adapt this to the PowerCMS inline editor. Is there a way to do the same thing with the PowerCMS live edit?
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../../../public_who_we_are/images/",
'FileName' => "staff_photo_".((isset($file_name))? $file_name :"")."",
'DefaultFileName' => "",
'ResizeType' => "2",
'ResizeWidth' => "200",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1_2 Start
$WA_UploadResult1_Params["WA_UploadResult1_2"] = array(
'UploadFolder' => "../../../public_who_we_are/images/",
'FileName' => "large_staff_photo_".((isset($file_name))? $file_name :"")."",
'DefaultFileName' => "",
'ResizeType' => "2",
'ResizeWidth' => "460",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_2 End
// WA_UploadResult1 Params End?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if($_SERVER["REQUEST_METHOD"] == "POST"){
WA_DFP_UploadFiles("WA_UploadResult1", "staff_photo", "0", "", "JPG:100", $WA_UploadResult1_Params);
$aws_key = $church_info->getColumnVal("s3_key"); //Change to new key
$aws_secret = $church_info->getColumnVal("s3_secret"); //Change to new secret
$client = S3Client::factory(array('credentials' => array('key' => $aws_key, 'secret' => $aws_secret), 'region' => 'us-east-1', 'version' => "2006-03-01", 'http' => ['verify' => false])); //eventually need to change out http when using ssl for https
foreach($WA_UploadResult1_Params as $key => $value) {
try{
$result = $client->putObject(array(
'ACL' => 'public-read',
'Bucket' => $bucket, //Bucket name
'Key' => 'public_who_we_are/images/'.$value['FileName'].'.jpg', //This is the S3 file name (use slash for folders ex. smallgroups/filename.jpg)
'SourceFile' => $value['UploadFolder'].''.$value['FileName'].'.jpg', //path to file
'StorageClass' => 'STANDARD',
));
}
catch(\Aws\S3\Exception\S3Exception $e) {
echo $e->getMessage();
}
}
//reference file using https://s3.amazonaws.com/$bucket/filename
}