从base64_decode图像中获取文件名

时间:2017-10-07 05:42:46

标签: php image laravel

图片将从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;
}

2 个答案:

答案 0 :(得分:1)

无法从base64格式获取文件名,因为它只包含构成图像的数据,而不是它的元数据。

答案 1 :(得分:1)

我在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);
}