Home > Backend Development > PHP Tutorial > Transfer files between high and low versions of curl

Transfer files between high and low versions of curl

WBOY
Release: 2016-07-28 08:28:13
Original
998 people have browsed it

In the past few days, I have to transfer files because I need to call the java interface. I chose curl to transfer files. One pitfall here is that I used the original @ followed by the absolute path of the file directly when transferring files.

However, there was no error, but it felt like it was never sent. Later, I tried it under win, and a warning was thrown directly saying that this method is outdated, please use the curlfile function instead. Only now did I realize that my computer had never turned on the warning and reported errors, but I had always turned it on under win. I had been struggling with this problem for some time.

Let’s look at the code below to see how curl transfers files and array data,

  $beforePath = '/Applications/MAMP/htdocs/photo/1.jpg'; 
        $afterPath = '/Applications/MAMP/htdocs/photo/2.jpg';//绝对路径
        $data = [
                
                'top' => curl_file_create($beforePath),
                'after' => curl_file_create($afterPath),
                'partnerId' => $data['0']['uid'],
                'mobile' => $data1['0']['phone'],
                'email' => $data1['0']['email'],
                'realName' => $data['0']['real_name'],
                
        ];
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //禁用证书
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, false);            
        curl_setopt($ch, CURLOPT_POST, true);  
        curl_setopt($ch,CURLOPT_BINARYTRANSFER,true);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
        curl_setopt($ch, CURLOPT_URL, $url);
        $info= curl_exec($ch);
        curl_close($ch);
Copy after login

The above introduces the high and low versions of curl to transfer files, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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