Sending File with cURL

后端 未结 1 1282
孤城傲影
孤城傲影 2021-01-17 05:33

I\'ve sent some post data with cURL and am now trying to send a file, getting lost along the way. I\'m using a form with a file input. Then would like cURL to send it off to

相关标签:
1条回答
  • 2021-01-17 06:16

    You are not sending the file that you got through the post request. Use the below code for posting the file through CURL request.

    $tmpfile = $_FILES['image']['tmp_name'];
    $filename = basename($_FILES['image']['name']);
    
    $data = array(
        'uploaded_file' => '@'.$tmpfile.';filename='.$filename,
    );
    
    $ch = curl_init();   
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    // set your other cURL options here (url, etc.)
    
    curl_exec($ch);
    

    For more reference check the below link Send file via cURL from form POST in PHP

    0 讨论(0)
提交回复
热议问题