I created a function in code igniter controller to return the file upon clicking download. It is working fine for every device but not on iPhone only. I couldn't understand what is the problem or what i am missing.
Only on iPhone devices it returns Garbage.
Controller method :
public function download_document($project_id,$file_name){
$doc_path=site_url('documents/projects/'.$project_id.'/'.$file_name);
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;
filename='.basename($doc_path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($doc_path));
ob_clean();
flush();
$file= readfile($doc_path);
// The PDF source is in original.pdf
return $file;
}
Output on calling method