I am using this code to download pdf file . its work fine in chrome but in mozila it create .htm file .Any can help me about this
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/pdf");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
readfile('phpToPDF/examples/pdf/'.$filename);
you need to terminate current script. that's why you are getting .htm extension on Mozilla.
use exit(); at the end of your code.
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/pdf");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Transfer-Encoding: binary");
readfile('phpToPDF/examples/pdf/'.$filename);
exit();
Related
I have a site with my hiking-tours:
https://pknudsen.net/gps/gpxviewer.php?gpstur=777
The routes are shown on a Google map. Google requires filetype "xml". I want to make a download-function so the users can get the tours to their gps. It requiers "gpx" file types. The download code is:
function myFunction($navn) {
$path = $navn;
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path); // outputs the content of the file
exit();
}
if (isset($_GET['name'])) {
$navn = $_GET['name'];
myFunction($navn);
}
How do i change the extension to "gpx"? I don't want to write the gpx-file on my server. Just to the user.
I would like to download a file from a folder on my server and automatically start the download without the person seeing the original file link.
Here is my current script, but it downloads an invalid corrupted file.
$filename = "dsk.zip";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename="./zz/'.$filename.'");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("./zz/".$filename));
ob_end_flush();
#readfile("./zz/".$filename);
Can you please help me? The file, dsk.zip, is in the folder zz.
$file = "dsk.zip"; // this is what you will get from a param (i.e. ?file=dsk.zip) or from DB query
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename='zz/'.$file");
header("Content-Length: ".filesize($file));
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
readfile('zz/'.$file);
i am trying to make the video seek using php file
this is my code
<?php
$path = 'http://exmaple.com/video.mp4';
$mm_type="video/mp4";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary
");
readfile($path); // outputs the content of the file
exit();
?>
the video work but it is not possible to seek
Seeking requires that your server support handling of the Content-Range: header
I have a document hosted in a folder above public_html for security reasons - moving the files into the web root is not an option.
I'm trying to access them via a readfile() but whatever I download winds up being 0 bytes and an empty file. I think the problem is that the "Content-Length" header isn't getting a correct value because filesize($target) is giving no output.
Any thoughts? Code included:
header('Content-Description: File Transfer');
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Transfer-Encoding: binary");
header("Pragma: public");
$file="../docs/$c/$path";
$size=filesize($file); //i think this line is the problem
header ("Content-Length: $size");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");
readfile($file_url);
I don't see $file_url defined in your code. Maybe it should be $file:
header('Content-Description: File Transfer');
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Transfer-Encoding: binary");
header("Pragma: public");
$file="../docs/$c/$path";
$size=filesize($file); //i think this line is the problem
header ("Content-Length: $size");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");
readfile($file);
I also don't see $filename defined.
After executing the below code, Browser automatically Downloading PDF Document. When i open that PDF, i am getting below Error.
I got below snippet idea from source
<?php
$filename = "yourfilename.pdf";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Transfer-Encoding: binary");
echo "my contents should display in PDF Document";
?>