douyou1901 2016-07-26 01:02
浏览 23
已采纳

PHP保存损坏的图像

I uploaded an image from iOS to cakephp by coding it to base 64 and this is my code on iOS :

UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    NSString *encodedString = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    modelMFront.text = encodedString;

then I get the image on cake and tried to saved :

$filename_path = 'test'.".jpg";
$decoded=base64_decode($this->request->data['model_mfront']);
file_put_contents(WWW_ROOT.$filename_path,$decoded);

the problem is that the image is damaged http://imgur.com/a/LESJ3

any idea how to fix this ?!

  • 写回答

1条回答 默认 最新

  • dongya0914 2016-07-27 04:45
    关注

    I fixed it . the problem was with the space when I encode the image so I had to replace the space by + in php

    $filename_path = 'test'.".jpg";
    $img = $this->request->data['model_mfront'];
    $img = str_replace(' ','+',$img);
    $decoded=base64_decode($img);
    file_put_contents(WWW_ROOT.$filename_path,$decoded);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析