Curl + php + restapi

Good Day

I am busy with a careers page on our website with restapi call to ERPNext.
I can create a job applicant, but not sure what is wrong with PHP/CURL coding not to upload file to Job Applicant?
My coding works well with GET/POST/PUT, but i thing its got to do with size of File that i do not know how to handle.

$ch = curl_init();

$data = array(“cmd” => “uploadfile”, “doctype” => “Job%20Applicant”, “docname” => $name." - “.$mail.” - ".$job, “filename” => “resume100.pdf”, “filedata” => $b64_data, “from_form” => 1, “isprivate” => 1);
$payload = json_encode($data);

curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_URL, ‘http://’.$host.‘/api/method’);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
‘Content-Type: application/json’,
'Content-Length: ’ . strlen($payload),
‘Content:’. $payload

$result = curl_exec($ch);

Hope anyone could help me out.

Thank You