File download problems-some word files are garbled or warning is displayed after being downloaded. the code is as follows. Please advise... $ Download]; get the ID & nbsp; $ connmysql_connect (localhost, root,) in the file database from the current page; * if (! $ Conn) & nbsp; {echo (& lt; B & gt; database connection file download problem-garbled characters or warnings are displayed after some word files are downloaded. the code is as follows. Please advise...
$ Id = $ _ GET ['download']; // obtain the ID of the file database from the current page.
$ Conn = mysql_connect ('localhost', 'root ','');
/* If (! $ Conn)
{
Echo ('
Database Connection failed!');
Exit;
}
Else echo'
Connection successful!';*/
$ Flag = mysql_select_db ('laborder', $ conn );
$ SQL = "select * from files where files_id = $ id ";
Mysql_query ("set names gbk ");
$ Result = mysql_query ($ SQL, $ conn );
$ Lists = mysql_fetch_array ($ result );
$ File_name = $ lists ["files_name"]; // get the file name
$ File_dir = "uploadfiles/"; // Mark the directory where the file is located
$ File = fopen ($ file_dir. $ file_name, "r"); // open the file
// Input file tag
Header ("Content-type: application/octet-stream ");
Header ("Accept-Ranges: bytes ");
Header ("Accept-Length:". filesize ($ file_dir. $ file_name ));
Header ("Content-Disposition: attachment; filename =". $ file_name );
Echo fread ($ file, filesize ($ file_dir. $ file_name ));
Fclose ($ file );
Exit;
------ Solution --------------------
PHP code
$ Contents = fread ($ file, filesize ($ file_dir. $ file_name); echo iconv ("UTF-8", "GBK", $ contents); fclose ($ file); exit;
------ Solution --------------------
Discussion
No worries!
Save the file as UTF8 without BOM