Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
Your IP : 3.138.120.112
<?php
require_once(_DIR_ . "/../../../aws/aws-autoloader.php");
use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
function uploadNationalityDoc($aobj_context){
$univcode = $aobj_context->mobj_data['univcode'];
$regno = $aobj_context->mobj_data['regno'];
$collcode = $aobj_context->mobj_data['collcode'];
$doc = $aobj_context->mobj_data['doc'];
$filename = $_FILES['file']['name'];
$tempdata = $_FILES['file']['tmp_name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(isset($filename) && $filename != ''){
$s3 = S3Client::factory(
array(
'credentials' => array(
'key' => IAM_KEY,
'secret' => IAM_SECRET
),
'version' => "latest",
'region' => 'ap-south-1'
)
);
$key = $univcode."/".$collcode."/".$doc."/".$regno.'.'.$ext;
try {
$res = $s3->putObject(['Bucket' => 'admission-certificates', 'Key' => $key, 'SourceFile' => $tempdata]);
if($res){
$arr['msg'] = 'successfully uploaded';
$arr['filepath'] = $key;
echo $aobj_context->mobj_output->ToJSONEnvelope($arr,0,"success");
}
} catch (S3Exception $e) {
$arr['message'] = 'Unable to upload photo';
echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
return;
}
}
}
?>
|