I want to upload a file using cURL. Since cURL requires a full file path, here is my code:
curl_setopt($ch, CURLOPT_POSTFIELDS, array("submit" => "submit", "file" => "@path/to/file.ext")); curl_exec($ch);
However, cURL will also post the full file path in the request header:
Content-Disposition: form-data; name = "file"; file name = "/path/to/file.ext"
But I want it to be simple
Content-Disposition: form-data; name = "file"; file name = "file.ext"
So, I change the code to
curl_setopt($ch, CURLOPT_POSTFIELDS, array("submit" => "submit", "file" => "@file.ext")); chdir("path/to");
And then cURL just gives an error message
could not open file "file.ext"
Can anyone tell me how to do this?
post php curl
Teiv
source share