Home > Backend Development > PHP Tutorial > Image upload in php yii2 interface

Image upload in php yii2 interface

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:19:37
Original
2117 people have browsed it

Now I am providing an interface to ios, and I have encountered some image upload problems. Now I can receive the base64-encoded data from ios. Do I need to decode it? What decoding process is required to upload the image to the server and obtain the URL from the server to store it in the database? Ask God for guidance. I wrote the interface under the yii2 framework

Reply content:

Now I am providing an interface to ios, and I have encountered some image upload problems. Now I can receive the base64-encoded data from ios. Do I need to decode it? What decoding process is required to upload the image to the server and obtain the URL from the server to store it in the database? Ask God for guidance. I wrote the interface under the yii2 framework

I used base64
yii2 processing when doing canvas image synthesis on the front end
1. Read the base64 encoded data => $data
2.$data = base64_decode($data);//data is binary data
3. Assume there is an upload folder in the web directory, and the file name is md5(microtime(true)).'.jpg' => $filename
4.file_put_contents(Yii::$app->basePath.'/web /upload/'.$filename,$data);
5.url = Yii::$app->urlManager->createAbsoluteUrl(['/']).'upload/'.$filename

Image upload in php yii2 interfaceImage upload in php yii2 interface

The first picture is the base64-encoded data sent from ios, and the second picture is the data output after decoding by my base64_decode(). These are my simulated http transfers on postman. Why is the decoded data garbled?

Related labels:
php
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template