【问题标题】:How to decode base64 in laravel 5.3如何在 laravel 5.3 中解码 base64
【发布时间】:2017-06-01 02:37:17
【问题描述】:

我正在开发一个用于移动应用程序的 API,我从移动端获取 base64 格式的图像并将其插入到我的 databaseprofile_image 列中

我想在我的网络中显示该图像,那么我该如何解码它

<div class="card horizontal card-driver-details">
    <div class="card-image card-circular">
        <img src="{{ $driver->profile_image}} "> //i want to display here
    </div>
    <div class="card-stacked">
        <div class="card-content">
            <p><b>Name:</b>{{ $driver->first_name }} {{ $driver->last_name }}</p>
            <p><b>Phone:</b>{{ $driver->phone_number }}</p>
            <p><b>Address:</b>{{ $driver->addess_city_village }} {{ $driver->address_state }}</p>
        </div>
    </div>
</div>

谢谢

【问题讨论】:

标签: php laravel api base64 laravel-5.3


【解决方案1】:

所有类型的文件都可以用这个解决,

  $image_64 = $data['photo_url']; //your base64 encoded data

  $extension = explode('/', explode(':', substr($image_64, 0, strpos($image_64, ';')))[1])[1];   // .jpg .png .pdf

  $replace = substr($image_64, 0, strpos($image_64, ',')+1); 

// find substring fro replace here eg: data:image/png;base64,

 $image = str_replace($replace, '', $image_64); 

 $image = str_replace(' ', '+', $image); 

 $imageName = Str::random(10).'.'.$extension;

 Storage::disk('public')->put($imageName, base64_decode($image));

【讨论】:

    【解决方案2】:

    试试这个。

    {{ base64_decode($driver->profile_image) }}
    

    这将使用 base 64 解码 profile_image,然后打印结果。

    【讨论】:

      【解决方案3】:

      我尝试了以下代码,但不起作用

      base64_decode($driver->profile_image);
      

      然后对此进行了一些浏览,然后现在找出所有更新的浏览器 支持data:image/jpeg/png/gif/etc

      所以现在我可以显示图像了

      $driver->profile_image
      

      【讨论】:

        【解决方案4】:

        试试这个:

        $image = base64_decode('base_64_image_string');
        $fp = fopen('path_to_where_you_want_to_save_image','wb+');
        fwrite($fp,$image);
        fclose($fp);
        

        【讨论】:

        • 感谢您的宝贵时间,我不想存储图像只是想解码和显示
        【解决方案5】:

        试试

        base64_decode($driver->profile_image);
        

        【讨论】:

        • 感谢您的宝贵时间,没有回复
        猜你喜欢
        • 2016-12-26
        • 1970-01-01
        • 2011-03-19
        • 2018-07-25
        • 1970-01-01
        • 2020-12-15
        • 1970-01-01
        • 1970-01-01
        • 2018-12-20
        相关资源
        最近更新 更多