代码如下:
function nochaoscode($encode, $str, $isemail = false) { $str = iconv($encode, "UTF-16", $str); for ($i = 0; $i $code = ord($str{$i}) * 256 + ord($str{$i + 1}); if ($code <128 and !$isemail) { $output .= chr($code); } else if ($code != 65279) { $output .= "&#".$code.";"; } } return $output; } $encode = $_POST['encode']; if ($encode == '') $encode = 'UTF-8'; if ($_FILES['file']['size'] > 0) { $data = nochaoscode($encode, file_get_contents($_FILES['file']['tmp_name'])); header ("Content-type: application/octet-stream;"); header ("Content-length: ".strlen($data)); header ("Content-Disposition: attachment; filename=".$_FILES['file']['name']); echo $data; } else { header ("Content-type: text/html; charset=UTF-8"); if ($_POST['email']) { echo htmlentities(nochaoscode($encode, $_POST['email'], true)); } else { echo htmlentities(nochaoscode($encode, $_POST['content'])); } ?> encode: file: encode: content: encode: email: } ?>