In doing micro-credit card using Curl Upload logo image, found an error:
failed creating formpost data
The array in the code is as follows:
$data = Array (' buffer ' => ' @test. jpg ');
Combined with the micro-letter to the document, check the syntax, seemingly did not find anything wrong ...
After the Internet search and verification, and finally found that the problem appears in @ here, if the @ preceded by a \ Escape on it, in the PHP official Bugs.php.net also mentioned (this article is the last to provide a URL)
Final code:
$data = Array (' buffer ' => ' \ @test. jpg ');
Solve the problem.
Bugs Address Reference: https://bugs.php.net/bug.php?id=50060
Let's look at one more example:
Before writing a PHP using Curl upload file code, today burst out a bug,curl error message for "Failed creating Formpost data"
Let's talk about the process of curl uploading files.
$file =array ("upimg" => "@/tmp/tmp.jpg");/file path, preceded by @, indicates file upload.
$url = ' http://localhosts/upload.php ';
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, curlopt_post,true);
curl_setopt ($ch, Curlopt_postfields, $file);
Curl_exec ($ch);
Here are two places to note:
1, $file must be an array
2, upload the file path before add @
3, the path must use the decision path
Now analyze the reason why the "failed creating Formpost data" error occurred
First of all soon to locate the cause of the problem is the path problem, analysis of the program code also found no problem, always do not solve
The reason for the last error log is that the data parameter in the Curl post submits a parameter that begins with the @ sign.
For example, to upload/tmp/tmp.jpg, and submit a profile, so the parameter value is path= '/tmp/tmp.jpg ', input profile desc= ' @test haha ';
According to the manual, there are two ways of submitting data curl Post
1.curl ($ch, Curlopt_postfield, Array (' pic ' => ' @/tmp/tmp.jpg ', ' filename ' => ' tmp ');
2.curl ($ch, Curlopt_postfield, ' pic=@/tmp/tmp.jpg&filename=tmp ')
The first method must be used in case of uploading files
curl($ch, CURLOPT_POSTFIELD, array('pic'=>'@/tmp/tmp.jpg', 'filename'=>'tmp');
So if the first character is at the @ character after the content will be resolved to address, if the address does not exist will throw the error, want to introduce DESC @test this path is non-existent
The second method only treats it as a normal string