Im trying to post to a multipart html form using CURLs CURLOPT_POSTFIELDS, but I cannot find out how to post it with no files.
When testing the form in normal browser, the “File” field can be empty, “Name” and “Message” can not.
This works:
$array = array(
"Name" => "Jon",
"Message" => "My package was broken, please send new.",
"File" => "@look_omg_its_broken_omgomg_look_at_the_corners.jpg"
);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $array);
This doesnt:
$array = array(
"Name" => "Jon",
"Message" => "My package was broken, please send new.",
"File" => ""
);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $array);
$output = curl_exec($ch);
This last $output results in a bool(false)
I have also tried these variations of values, but no success.
"File" => "@"
"File" => "@/"
"File" => NULL
"File"
"File" => array("")
"File" => array("filename" => "")
Anyone know better?
Without refactoring your backend or emulating a multi-part form submission manually I’m pretty sure you won’t be able to solve your problem with any
CURLOPT_POSTFIELDSlogic alone, also see:http_request_body_encodeIf you insist on trying to solve this using CURL alone, I suggest you inspect the ext/curl source code.