blackcell Posted July 28, 2015 Share Posted July 28, 2015 I need to send a cURL request containing a file to upload as well as a JSON string. I can get a properly formatted request when sending the JSON, but the file is throwing it off. $curl_file_object = '@'.$tmp_name $postData= array( 'JSON'=> json_encode($jsonParams), $reference => $curl_file_object, ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $target); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // stop verifying certificate curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data;")); curl_setopt($curl, CURLOPT_POST, true); // enable posting curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); // post data curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); // if any redirection after upload $response = curl_exec($curl); $info = curl_getinfo($curl); curl_close($curl); debug($info); Am I the first one needing to send file binary data along with a json string to a server at the same time? Quote Link to comment https://forums.phpfreaks.com/topic/297526-php-and-curl-multiform-request-with-file-and-text/ Share on other sites More sharing options...
NotionCommotion Posted July 29, 2015 Share Posted July 29, 2015 Sorry, no direct answer. But instead of sending the file, maybe send the URL of the file, and have the responded get it? Quote Link to comment https://forums.phpfreaks.com/topic/297526-php-and-curl-multiform-request-with-file-and-text/#findComment-1517606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.