Reputation: 132
Hi I want to upload image in s3, I have byte array. How i can convert byte array to a temporary url on the fly?
$byte_arr = 'iVBORw0KGgoAAAANSUhEUgAAACIAAAAhCAYAAAHL1En6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAK
T2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AU
kSYqIQkQSogh';
//$file_content = 'data:image/jpeg;base64, $byte_arr';
//echo "<img src='data:image/jpeg;base64, $byte_arr' />";die;
$s3->putBucket("bucketname", S3::ACL_PUBLIC_READ);
$fileName = 'user_1.jpg';
//move the file
if ($s3->putObjectFile($file, "bucketname", $fileName, S3::ACL_PUBLIC_READ)) {
echo "We successfully uploaded your file.";
}else{
echo "Something went wrong while uploading your file... sorry.";
}
so my question is how to get $file from byte array. I need tmp_url for it.
Upvotes: 3
Views: 2325
Reputation: 2169
You can use imagecreatefromstring() function:
$data = base64_decode($byte_arr);
$formImage = imagecreatefromstring($data);
Upvotes: 1