图像将从 mobile api
中的 base64
类型,我正在尝试从中获取图像名称 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;
}
It is not possible to get the filename from base64 format, as this only contains the data that makes up the image, not it's metadata.
I have used this code in slim
php framwork to save image to desired folder
$img= base64_decode($val_pic);
$image_name= "test.jpg"; /* name image*/
if( $file = fopen("folder/".$image_name, 'wb')){
fwrite($file, $img);
fclose($file);
}