<?php$realname = "Zhuast.exe"; Original file name $filename = "Chinese filename. exe"; FileName downloaded to the browser $encoded_filename = UrlEncode ($filename); $encoded _filename = Str_replace ("+", "%20", $encoded _filename); $ua = $_server["Http_user_agent"];if (Preg_match ("/msie/", $ua) | | preg_match ("/trident\/7.0/", $ua)) {header (' Content-disposition:attachment; Filename= "'. $encoded _filename. ‘"‘);} else if (Preg_match ("/firefox/", $ua)) {header (' content-disposition:attachment; filename*= ' utf8\ ' \ '. $filename. ‘"‘);} else {header (' content-disposition:attachment; Filename= '. $filename. ‘"‘);} Header ("Content-type:application/octet-stream"); Header ("Content-transfer-encoding:binary"); Header (' Content-length: '. FileSize ($realname)); Specifies the size of the downloaded file//reads the contents of the file and outputs it directly in order to download the ReadFile ($realname); >
PHP attachment more than 3 bytes problem, save PHP file, to choose Utf-8 No BOM format, if PHP file has BOM, generated EXE will also have BOM
PHP service generation exe attachment download