Answer the question
In order to leave comments, you need to log in
Why does the php script that gives the file to the user fall apart?
Faced a problem of the following character:
There is a tif or mdi file lying on the server.
When you try to give the file to the user, via the web, the script falls off on the output.
The code is something like this:
header('Content-Description: File Transfer');
header('Content-Type: ' . $file_mime_type);
header('Content-Disposition: attachment; filename="' . $file_name . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . $file_size);
echo file_get_contents("path/to/file.tif");
echo
. echo
with or does not solve the problem.
Turning on the output of all errors does not give any result, no errors are displayed.
The output of other types of files - pdf/docx/xlsx/other works, the file is correctly given to the user for download
According to the apache logs, the user receives exactly as many bytes as the problem file itself weighs, but the browser displays "Unable to display the page"
There is a suspicion that the matter is in binary representation of tif and mdi, but what exactly - I can not dig up.
Thanks to all who responded. print(file_get_contents("path/to/file.tif"))
readfile("path/to/file.tif")
Answer the question
In order to leave comments, you need to log in
Try the following edits:
1. header("Content-Type: application/force-download");
2. readfile("path/to/file.tif"); exit();
try this way, by analogy
$file = ("../add/price.docx");
header ("Content-Type: application/octet-stream");
header ("Accept-Ranges: bytes");
header ("Content-Length: ".filesize($file));
header ("Content-Disposition: attachment; filename=".$file);
readfile($file);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question