使用字节数组在s3中上传图像

时间:2016-04-28 09:03:30

标签: php codeigniter amazon-s3

嗨我想在s3上传图片,我有字节数组。 如何将字节数组转换为临时URL?

$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.";
    }

所以我的问题是如何从字节数组中获取$ file。我需要tmp_url。

1 个答案:

答案 0 :(得分:0)

您可以使用imagecreatefromstring()功能:

 $data = base64_decode($byte_arr);
 $formImage = imagecreatefromstring($data);