I am trying to upload a file using a RESTful web service as follows:
$filename = "pathtofile/testfile.txt"; $handle = fopen($filename, "r"); $filecontents = fread($handle, filesize($filename)); fclose($handle); $data = array('name' => 'testfile.txt', 'file' => $filecontents); $client = curl_init($url); curl_setopt($client, CURLOPT_POST, true); curl_setopt($client, CURLOPT_POSTFIELDS, $data); curl_setopt($client, CURLOPT_RETURNTRANSFER, 1); curl_close($client);
But I keep the gettig file empty as the answer for this request.
I also tried sending the file path, for example:
$data = array('name' => 'testfile.txt', 'file' => 'pathtofile/testfile.txt'); curl_setopt($client, CURLOPT_POSTFIELDS, $data);
Or: just send the contents of the file just like this:
curl_setopt($client, CURLOPT_POSTFIELDS, $filecontents);
But the same answer: the file is empty .
Note that: the file exists and is not empty, and I'm just trying to download the file without additional fields.
I saw this post , but the same problem, any ideas?