格式错误的utf-8字符可能编码错误

时间:2016-10-08 11:20:07

标签: php laravel encoding utf-8

我已将图像编码到iOS中的base64并将其发送到服务器,然后在该字符串上使用base64_decode()。但是它给出了一个错误

  

格式错误的utf-8字符可能编码错误

我在laravel中使用php核心功能;

public function createIdea(Request $request) {
   $filename = str_random(8);
   $imageStr = $request->input('idea_image');
   $decodeImage = base64_decode($imageStr);
   $image = imagecreatefromstring($decodeImage);
     if ($request->hasFile($image)) {
          $filename = $request->file($image)->getClientOriginalName();
          $moveImage = $request->file($image)->move('images', $filename);
     }
   $idea = new Idea();
   $idea->idea_title = $request->input('idea_title');
   $idea->idea_info = $request->input('idea_info');
   $idea->idea_image = "images/".$filename;
   $idea->idea_location = $request->input('idea_location');
   $idea->idea_description = $request->input('idea_description');
   $idea->idea_description = $request->input('selection');
   $idea->user_id = \Auth::id();
   $idea->save();
   $ideaId = $idea->id;
     if ( ! $idea->id ) {
          $statusCode =404;
          response()->json(array('Status:' => 'Idea Creation FAILED'),$statusCode);
    }else{
          $response = $idea->toJson();
          $statusCode =200;
          return response()->json(array('Status:' => 'Idea Created Successfully', 'ideaId' => $ideaId, 'image' => $imageStr),$statusCode);
}

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

在以任何语言提供数据之前,先

在base64中对blob进行编码,这将使您可以将BLOB数据作为安全字符串进行传输!