<?PHP/** * Download File * Header function **/Dl_file ($_get[' filename ']);functionDl_file ($file){ $file= ".//images//".$file; //First , see if the file exists if(!Is_file($file )) { die("<b>404 File not Found!</b>" ); } //Gather relevent info about file $len=filesize($file ); $filename=basename($file ); $file _extension=Strtolower(substr(STRRCHR($filename, "."), 1 ) ); //This would set the Content-type to the appropriate setting for the file Switch($file _extension) { Case"PDF":$ctype= "Application/pdf"; Break; Case"EXE":$ctype= "Application/octet-stream"; Break; Case"Zip":$ctype= "Application/zip"; Break; Case"Doc":$ctype= "Application/msword"; Break; Case"XLS":$ctype= "Application/vnd.ms-excel"; Break; Case"ppt":$ctype= "Application/vnd.ms-powerpoint"; Break; Case"GIF":$ctype= "Image/gif"; Break; Case"PNG":$ctype= "Image/png"; Break; Case"JPEG": Case"JPG":$ctype= "Image/jpg"; Break; Case"MP3":$ctype= "Audio/mpeg"; Break; Case"WAV":$ctype= "Audio/x-wav"; Break; Case"MPEG": Case"MPG": Case"MPE":$ctype= "Video/mpeg"; Break; Case"MOV":$ctype= "Video/quicktime"; Break; Case"Avi":$ctype= "Video/x-msvideo"; Break; //The following is for extensions that shouldn ' t is downloaded//(sensitive stuff, like PHP files) Case"PHP": Case"HTM": Case"HTML": Case"TXT": die("<b>cannot is used for".)$file _extension. "Files!</b>" ); Break; default:$ctype= "Application/force-download"; } $file _temp=fopen($file, "R" ); //Begin Writing Headers 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" ); //Use the switch-generated content-type Header("Content-type:$ctype" ); //Force the download $header= "content-disposition:attachment; Filename= ".$filename. ";"; Header($header ); Header("Content-transfer-encoding:binary" ); Header("Content-length:".)$len ); //@readfile ($file); Echo fread($file _temp,filesize($file ) ); fclose($file _temp ); Exit ();}?>
PHP Download file