I have a script where I get the contents of the file and then echo it to the screen, the problem is that it actually echos the binary file to the page, what I want, if for it to act as a download, the download dialog will be displayed.
how can i achieve this
From the PHP header () manual :
// We'll be outputting a PDF header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="downloaded.pdf"'); // The PDF source is in original.pdf readfile('original.pdf');
Change the content type and file name. You can read the user file through get_contents_file, but either work or work.
, Content-disposition. . . .
Content-disposition
Content-type application/octet-stream, .
Content-type
application/octet-stream
(: application/binary, , , , application/octet-stream, " Content-Type , application/octet-stream [...], - . , - ". : Google).
application/binary
Content-Type HTTP.
"" PHP (.. - ) :
header("Content-Type: application/octet-stream");
script, - .
Thanks @Brad for the answer. I made some changes to it. What I found is that my content is repeated, not "read file". I have done it.
header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="download.pdf"'); $pdf = $thirdPartyAPI->getPdf($ID); echo $pdf; ob_clean(); flush(); exit;
Source: https://habr.com/ru/post/1756795/More articles:Custom alternative to html - htmlHow to force EntityDataSource to allow me access to child objects? - asp.netTypeLoadException not caught by try / catch method - c #__IPHONE_OS_VERSION_MIN_REQUIRED, please explain - iosThe default controller does not load after redirection - codeigniterYAML - one-many object schedules - yamlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1756797/save-remote-file-that-pushes-headers-to-force-download&usg=ALkJrhgg5sW_RnoGb3yHQH96TY8VSV7LGwPython web server - performing other tasks - pythonLINQ-to-SQL stored procedure problem - .netNUnit 2.5.6 + PartCover 2.0 / 4.0 = My classes are not shown - c #All Articles