Tp框架如何接受ios端post过来的base64编码的图片 并且把图片路径保存
谢谢求大牛指点 最好有代码
回复内容:
Tp框架如何接受ios端post过来的base64编码的图片 并且把图片路径保存
谢谢求大牛指点 最好有代码
直接把解码后存入指定目录的文件就行,
接收到的base64数据:
$data = "data:image/jpg;base64,balabalabala...";
类似这种格式, 先把’,’前面的东西去掉, 得到文件内容
$image_content = "balabalabala...";
然后执行
$image_content = base64_decode($image_content);
然后执行
file_input_contents($dir, $image_content)
$dir就是你要保存图片的地址
$base = 'data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAEoAAAAoCAMAAABuMpwSAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAK5QTFRF/+/IqJmZuN//qKjI7///78iomZmZ///fuJmZmbjf/9+4///vyKioyO//qMjvqLjfmZm43///majIyKi4yKiZ37iZqMjIqJmo37iombjIuJm4uLjfmZmoqJm43//v3//f/+/vmbi4uKi4uKiZ37i4yMioqMjfyO/fuLiZ1LiZqKiouKjIuMjv3+/IuMjfyLjI7//f79+4yMi4uKiouN/vqLi439+4yLiouLi45PPwawAAAAFiS0dEAIgFHUgAAAIlSURBVEjH7VVpc9MwEJWtWnJsUx+xFdqUtjSEUGjDUc7//8d4uyulIVbT8IUZZrKZcWzZ+/T27SGljna0qCWplv+TzFgxLOSTQqmykE+qF6dq687UxtYRJO9eMJZKGr/YdspDBXzYNOP3JoaDzXm5ZE8QDKSqvquG8KCcDqT6zmhlZhM7opW8PC1rVQ3YHZ54e0b8NaOc9x1YwZPp5nOmqfMLZ4VyNMJXogRJsAnksqsCVDWQdgzlGCVIOBK97YxgbUsAsa4ClGmvJ7wDPnudEbebCYu7wwgEgkCAMp5UvlhcL97IOm0WWOUbzKjuvO4KYrV8q31VrPpNgGfv5hsowyrhHgLsIrm2g/SO84RiMR5qiehCMQiKQNHWOkgWU8tKrpHyECBlPQZ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