Posted by: Anil Kumar Panigrahi in: ● June 19, 2010
In this post, i want to explain download any file using php script.It will useful when we are developing a website like In that website have list of files and users can download those files.
Script is as follows:
<?php
$filename = ‘[file name].[extension]‘;$ctype=”application/[extension]“;
// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);header(“Pragma: public”); // required
header(“Expires: 0″);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0″);
header(“Cache-Control: private”,false); // required for certain browsers
header(“Content-Type: $ctype”);// change, added quotes to allow spaces in filenames
header(“Content-Disposition: attachment; filename=\”".basename($filename).”\”;” );
header(“Content-Transfer-Encoding: binary”);
header(“Content-Length: “.filesize($filename));
readfile(“$filename”);
exit();?>
We can write this script for all types of files. We write this script in a function and just we pass the files with complete path. In this way we can use this script.
Hope it will be useful.
1 | forex robot
20 de June de 2010 to ● 12:30 pm
Wow this is a great resource.. I’m enjoying it.. good article
Comments