I want to add option to download attach file from every request of my first API -> url: APIno1{title, id, type, filetype} but my attach files are in different API -> url: API2?id=’$ID’&type=’$TYPE’ , that API2 may response different type of base64 file (pdf or Rar or Png …) but i have file type in first api my code is:
one part of application that user click to download attach
the button from APIno1:
foreach ($data['receptionHeader']['attachList'] as $item){
$details .= '<tr>';
$details .= '<input type="hidden" name="ID" value="'.$item['ID'].'">';
$details .= '<input type="hidden" name="Type" value="'.$item['Type'].'">';
$details .= '<input type="hidden" name="FileType" value="'.$item['FileType'].'">';
$details .= '<input type="submit" name="Title" value="'.$count_item . '-' . $item['Title'].'" class="btn btn-primary p-1 mt-2" style="margin: 3px; padding: 3px;">';
$details .= '</tr>';
$count_item++;
}
and the code to download base64 attach file:
function showFile ($ID, $Type){
$url_req = "...ion/getFile?ID=".$ID."&Type=".$Type;
#### دریافت اطلاعات از سرور
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_req);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$basedecode = base64_decode($result);
return $basedecode;
}
if (isset($_POST['Title'])){
if (!empty($_POST['ID']) and !empty($_POST['Type'])){
$fileparamID = $_POST['ID'];
$fileparamType = $_POST['Type'];
$fileparamFileType = $_POST['FileType'];
$fileType = "pdf";
$decoded = showFile (112714, 2);
$file = 'itrac-attach-download-file.'.$fileType;
file_put_contents($file, $decoded);
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
}
}
but it does not work , can anybody help me?
I didnot try anything else but my form just post but not work
kamyar nikdehghan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.