todo:编码问题

hotfix/远程访问多媒体中心
LMR 7 years ago
parent 1bb7907cd9
commit 941cc61f20

@ -362,25 +362,42 @@ class Info_amp extends CI_Controller
public function handel_word_source() {
$file = $_FILES['file'];
if (!$file) return;
if (!$file) {
echo(json_encode(array(
'status' => 'error',
'msg' => "文件上传失败。"
)));
return;
}
//转移文件
$md5_name = md5($file["name"]).strrchr($file["name"],'.');
$md5_file = md5($file['name'].$file['size']);
//ext
$ext = mb_strtolower(strrchr($file["name"],'.'));
if ($ext != '.docx') {
echo(json_encode(array(
'status' => 'error',
'msg' => '只能接收word(.docx)文档。'
)));
return;
}
$md5_name = $md5_file.$ext;
$path = realpath('../cht-system/views/information/word_source').'/'.basename($md5_name);
if (move_uploaded_file($file['tmp_name'], $path)) {
$msg = "file path: ".$path;
} else {
$msg = "file upload error!";
}
if($file) {
$this->load->library('wordphp');
$rt = new WordPHP();
$rt->img_dir = realpath('../cht-system/views/information/word_img');
$rt->img_prex = $md5_file;
$html = $rt->readDocument($path);
$html = str_ireplace($rt->img_dir, '//202.103.68.62:9096/information-view/information/word_img', $html);
echo(json_encode(array(
'status' => 'success',
'msg' => $msg
'path' => $path,
'html' => $html
)));
} else {
echo(json_encode(array(
'status' => 'error',
'msg' => $msg
'msg' => "word文件解析失败。"
)));
}
}

@ -37,10 +37,13 @@ class WordPHP
private $file;
private $rels_xml;
private $doc_xml;
private $doc_media = [];
private $doc_media = array();
private $last = 'none';
private $encoding = 'ISO-8859-1';
private $tmpDir = 'tmp';
//图片目录和前缀
public $img_dir = '';
public $img_prex = '';
/**
* CONSTRUCTOR
@ -167,7 +170,8 @@ class WordPHP
if($reader->name == "w:shd" && $reader->getAttribute("w:val") != "clear" && $reader->getAttribute("w:fill") != "000000") {
$f .="background-color: #".$reader->getAttribute("w:fill").",";
}
if($reader->name == 'w:drawing' && !empty($reader->readInnerXml())) {
$temp_rx = $reader->readInnerXml();
if($reader->name == 'w:drawing' && !empty($temp_rx)) {
$r = $this->checkImageFormating($reader);
$img = $r !== null ? "<image src='".$r."' />" : null;
}
@ -283,7 +287,13 @@ class WordPHP
$ext = strtolower($arr[$l-1]);
$im = imagecreatefromstring($image);
$fname = $this->tmpDir.'/tmp/'.$relId.'.'.$ext;
if (empty($this->img_dir)) {
$fname = $this->tmpDir.'/tmp/'.$relId.'.'.$ext;
} else {
$ext = str_ireplace('jpeg', 'jpg', $ext);
$fname = $this->img_dir.'/'.$this->img_prex.'_'.mb_strtolower($relId).'.'.$ext;
}
switch ($ext) {
case 'png':
@ -404,7 +414,7 @@ class WordPHP
$tc2 = new SimpleXMLElement($tc->readOuterXML());
foreach ($tc2->children('w',true) as $ch) {
if (in_array($ch->getName(), ['left','top','botom','right']) ) {
if (in_array($ch->getName(), array('left','top','botom','right'))) {
$line = $this->convertLine($ch['val']);
$style .= " border-".$ch->getName().":".$ch['sz']."px $line #".$ch['color'].";";
}
@ -418,16 +428,16 @@ class WordPHP
private function convertLine($in)
{
if (in_array($in, ['dotted']))
if (in_array($in, array('dotted')))
return "dashed";
if (in_array($in, ['dotDash','dotdotDash','dotted','dashDotStroked','dashed','dashSmallGap']))
if (in_array($in, array('dotDash','dotdotDash','dotted','dashDotStroked','dashed','dashSmallGap')))
return "dashed";
if (in_array($in, ['double','triple','threeDEmboss','threeDEngrave','thick']))
if (in_array($in, array('double','triple','threeDEmboss','threeDEngrave','thick')))
return "double";
if (in_array($in, ['nil','none']))
if (in_array($in, array('nil','none')))
return "none";
return "solid";

Loading…
Cancel
Save