I want to upload a file using cURL. Since cURL requires full path to the file so 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 this full path of the file in the request header:
Content-Disposition: form-data; name="file"; filename="/path/to/file.ext"
But I want it to be just
Content-Disposition: form-data; name="file"; filename="file.ext"
So I change the code to
curl_setopt($ch, CURLOPT_POSTFIELDS, array("submit" => "submit", "file" => "@file.ext"));
chdir("path/to"); # change current working directory to where the file is placed
curl_exec($ch);
chdir("path"); # change current working directory back
And then cURL simply throws an error message
couldn't open file "file.ext"
Can anybody tell me how to do it please?