PHP method sample code for receiving file stream sent by App

怪我咯
Release: 2023-03-14 11:36:02
Original
2000 people have browsed it

This article mainly introduces the method of PHP receiving App side to send file stream, involving PHP curl-based file transfer operation related skills, friends in need can refer to it

The example of this article tells the PHP receiving App side Method for sending a file stream. Share it with everyone for your reference, the details are as follows:

Solution ideas:

1. The client uploads multiple pictures in a loop, with parameters and combinations using certain rules Produce data stream (picture data is placed at the end)
2. Use data stream for transmission, and the php server uses file_get_content('php://input') to receive
3. After the transmission is completed, the data stream will be processed according to the rules Split, take out the last picture data, and write it into the picture file

Sample code:

The following code is to send a single picture and parameter PHP file. Multiple pictures can be Loop call.

 $pic_data, // 这里存放图片数据 ]; // 使用 '#####' 进行分割数组 $strData = implode('#####', $data); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); //设置头文件的信息作为数据流输出 curl_setopt($curl, CURLOPT_HEADER, 0); //设置获取的信息以文件流的形式返回,而不是直接输出。 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //设置post方式提交 curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $strData); $data = curl_exec($curl); curl_close($curl); // 显示post的返回值 echo ($data);
Copy after login

Receive the PHP file requested by curl and return the json format


        
Copy after login

The above is the detailed content of PHP method sample code for receiving file stream sent by App. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!