PHP implements file download,
<? Php/*** parameter description: ** $ file_name file name (Chinese and English) * $ _ SERVER ['document _ root'] obtain the path of apache **/function download ($ file_name) {// transcode the Chinese file name $ file_name = iconv ("UTF-8", "GB2312", $ file_name); // file absolute path: E:/wamp/www. "/Demo/Object/DownfileSource/" .qq.txt $ filepath = $ _ SERVER ['document _ root']. "/Demo/Object/DownfileSource /". $ file_name; if (! File_exists ($ filepath) {// check whether the file exists echo "this file does not exist! "; Return ;}$ fp = fopen ($ filepath, 'R'); // open the file $ file_size = filesize ($ filepath ); // calculate the file size if ($ file_size> 1) {echo "<script> window. alert ('file is too large, you do not have permission to download ') </script> "; return;} // HTTP header information header (" Content-type: application/octet-stream "); header (" Accept-Ranges: bytes "); header (" Accept-Length :". $ file_size); header ("Content-Disposition: attachment; filename = ". $ file_name); // echo fread ($ fp, $ file _ Size); $ buffer = 1024; // for download security, make a file byte read counter $ file_count = 0; // determine whether the file ends feof while (! Feof ($ fp) & ($ file_size-$ file_count> 0) {$ file_data = fread ($ fp, $ buffer ); // count the number of bytes read $ file_count + = $ buffer; echo "$ file_data"; // send the data to the browser} fclose ($ fp );} // call download ("qq.txt"); // you only need to fill in the file name?>