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
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>
Similar to this format, first remove the thing in front of ',' to get the file content
<code>$image_content = "balabalabala...";</code>
Then execute
<code>$image_content = base64_decode($image_content);</code>
Then execute
<code>file_input_contents($dir, $image_content)</code>
$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/SO84RiMR5qiehCMQiKQNHW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