gpt4 book ai didi

php - 从 base64_decode 图像中获取文件名

转载 作者:行者123 更新时间:2023-12-04 16:46:55 25 4
gpt4 key购买 nike

图像将从 mobile apibase64 类型发送,我正在尝试从 base64_decoded 图像文件中获取图像名称。我怎样才能得到它?

$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);

$im = imagecreatefromstring($data);

这是我试图用 laravel 写的图像名称的功能

   public function completeProfile($session_id,$username,$fullname,$position,$image){
$user = JWTAuth::toUser($session_id);
$userid = $user->id;
$img = base64_decode($image);
if(file_put_contents(public_path().'/images/users',$img)){
$result = $this->repository->completeProfile($userid,$username,$fullname,$position,$image);
}
return false;
}

最佳答案

我在 slim php 框架中使用了这段代码来将图像保存到所需的文件夹

$img= base64_decode($val_pic);
$image_name= "test.jpg"; /* name image*/


if( $file = fopen("folder/".$image_name, 'wb')){
fwrite($file, $img);
fclose($file);
}

关于php - 从 base64_decode 图像中获取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46617068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com