Home > Backend Development > PHP Tutorial > How does the Tp framework accept the base64-encoded image posted from the ios side and save the image path?

How does the Tp framework accept the base64-encoded image posted from the ios side and save the image path?

WBOY
Release: 2016-09-22 08:56:52
Original
1612 people have browsed it

How does the Tp framework accept the base64 encoded image posted from the ios side and save the image path

Thank you for asking for advice. It’s best to have code

Reply content:

How does the Tp framework accept the base64 encoded image posted from the ios side and save the image path

Thank you for asking for advice. It’s best to have code

Just store the decoded file in the specified directory directly,

Received base64 data:

<code>$data = "data:image/jpg;base64,balabalabala...";</code>
Copy after login

Similar to this format, first remove the thing in front of ',' to get the file content

<code>$image_content = "balabalabala...";</code>
Copy after login

Then execute

<code>$image_content = base64_decode($image_content);</code>
Copy after login

Then execute

<code>file_input_contents($dir, $image_content)</code>
Copy after login

$dir is the address where you want to save the picture

<code class="php"><?php
$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/SO84RiMR5qiehCMQiKQNHWOkgWU8tKrpHyECBlPQZVDcBAfkHgJBvBkOOjdp7VDtRtyOx7DRcoUtpouR/t/zduh4Kujx1BM66kAsBA+UDt04QR9NRYEKg7mnm4wr+UMchQyT1+jcIYctyhXJamOICVQNXS+Fz0y/XHT5/vvswuAEVFW04ztxfpT1a11Dix4jZqHx5W/a20lozHg6GIIE1WOg/yrylcKcBvg10NJKUZT6p9ARaYy6zV5foe0ohWZa22j56DA0wa3Mo50a5TDGqC8ueG1fuhkJ+xVkmDDH6f/7DFX7FyRaQYUn7wAa5+puEQ2a+VdjMM82k2YhXqqqTyfZaVDGriFszw3szqfLC/qMLphHwe6mj/xH4DIIIqf4p44pEAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTYtMDYtMTNUMTU6MzM6MjArMDg6MDBOXtEYAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE2LTA2LTEzVDE1OjMzOjIwKzA4OjAwPwNppAAAAABJRU5ErkJggg==';

file_put_contents('1.jpg', file_get_contents($base));</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template