Can anyone give me an example for PHP's CURLFile class?

前端 未结 5 1897
小鲜肉
小鲜肉 2020-12-02 11:16

I had a very simple PHP code to upload a file to a remote server; the way I was doing it (as has been suggested here in some other solutions) is to use cUrl to upload the fi

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 12:00

    FOR curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please usethe CURLFile class instead

    $img='image.jpg';
    
    $data_array = array(
            'board' => $board_id,
            'note' => $note,
            'image' => new CurlFile($img)
        );
    
    $curinit = curl_init($url);
         curl_setopt($curinit, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curinit, CURLOPT_POST, true);
         curl_setopt($curinit, CURLOPT_CUSTOMREQUEST, "POST");
         curl_setopt($curinit, CURLOPT_POSTFIELDS, $data_array);
         curl_setopt($curinit, CURLOPT_SAFE_UPLOAD, false);
         $json = curl_exec($curinit);
         $phpObj = json_decode($json, TRUE);  
         return $phpObj;
    

提交回复
热议问题