File openen in pagina
Auteur: php.net - 14 december 2008 - 11:36 - Gekeurd door: Stijn - Hits: 3969 - Aantal punten: (0 stemmen)
Ik kwam dit script tegen op php.net en ik vond hem zeer handig.
Als je bijv. een downloadsysteem op je site hebt, is dit handig omdat je dan onzichtbaar een file in een pagina kan openen.
|
Code: |
<?php
function download($path) {
// fix for IE catching or PHP bug issue
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
// browser must download file from server instead of cache
// force download dialog
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// use the Content-Disposition header to supply a recommended filename and
// force the browser to display the save dialog.
header("Content-Disposition: attachment; filename=".basename($path).";");
/*
The Content-transfer-encoding header should be binary, since the file will be read
directly from the disk and the raw bytes passed to the downloading computer.
The Content-length header is useful to set for downloads. The browser will be able to
show a progress meter as a file downloads. The content-lenght can be determines by
filesize function returns the size of a file.
*/
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($path));
@readfile($path);
}
?>
<?php function download($path) { // fix for IE catching or PHP bug issue header("Expires: 0"); // set expiration time header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); // browser must download file from server instead of cache // force download dialog header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download"); // use the Content-Disposition header to supply a recommended filename and // force the browser to display the save dialog. header("Content-Disposition: attachment; filename=".basename($path).";"); /* The Content-transfer-encoding header should be binary, since the file will be read directly from the disk and the raw bytes passed to the downloading computer. The Content-length header is useful to set for downloads. The browser will be able to show a progress meter as a file downloads. The content-lenght can be determines by filesize function returns the size of a file. */ header("Content-Transfer-Encoding: binary"); } ?>
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|