1. For general
$file = "/tmp/dummy.tar.gz"; Header ("Content-type:application/octet-stream"); Header basename ($file). "'); Header filesize ($file)); ReadFile ($file);
2. The name of the downloaded file is in Chinese, the user will be able to download after the garbled
$file= "/tmp/Chinese name. tar.gz";$filename=basename($file);Header("Content-type:application/octet-stream");//working with Chinese file names$ua=$_server["Http_user_agent"];$encoded _filename=Rawurlencode($filename);if(Preg_match("/msie/",$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-length:".)filesize($file));ReadFile($file);
3. We can do it without readfile.
$file= "/tmp/Chinese name. tar.gz";$filename=basename($file);Header("Content-type:application/octet-stream");//working with Chinese file names$ua=$_server["Http_user_agent"];$encoded _filename=Rawurlencode($filename);if(Preg_match("/msie/",$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. ‘"‘);}//let xsendfile send filesHeader("X-sendfile:$file");
PHP File download code