So I've been trying to upload a file via Curl. I have a txt file on my local server in the root directory. When I try it, it says that the file was uploaded successfully but, the text inside the txt isn't the same as the txt file I have.
$postData = array(
'folderId' => '3276800',
'filename' => 'TxT_12323.txt',
'filedata' => '@847327489732984.txt',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://192.168.1.103/services/rest/document/upload");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_USERPWD, "admin" . ":" . "admin");
$result = curl_exec($ch);
if (curl_errno($ch))
{
echo 'Error:' . curl_error($ch);
exit();
}
echo "Upload Successful!<br><br>Return: " . $result;
curl_close($ch);
File that is uploaded is suppose to have the same inner text as 847327489732984.txt but, when opening the .txt it just has "@847327489732984.txt" inside it.
So, it's not uploading the file correctly.
I fixed this by instead of
'filedata' => '@847327489732984.txt'
I did
'filedata' => file_get_contents('123.pdf')
suppose to have the same inner text as 847327489732984.txt
. I suggest reading the file into a variable and sending that as the data. If this is handled on the server the upload is sent to, then the code there must be checked.you can't really do that with PDFs
why not? Files are just string data, doesn't matter the type of file.