From 98f000e4c9ba6be697f9b78511f289b957397017 Mon Sep 17 00:00:00 2001 From: LMR <59361885@qq.com> Date: Tue, 8 Jan 2019 16:43:14 +0800 Subject: [PATCH] add copy --- application/controllers/info_amp.php | 47 ++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/application/controllers/info_amp.php b/application/controllers/info_amp.php index 8f06663e..ca8c35bf 100644 --- a/application/controllers/info_amp.php +++ b/application/controllers/info_amp.php @@ -381,23 +381,52 @@ class Info_amp extends CI_Controller return; } $md5_name = $md5_file.$ext; - $path = realpath('../cht-system/views/information/word_source').'/'.basename($md5_name); + //临时docx文件 + $docx_path = realpath('../cht-system/views/information/word_source').'/'.basename($md5_name); $html = 'to use mammoth'; - if (move_uploaded_file($file['tmp_name'], $path)) { + if (move_uploaded_file($file['tmp_name'], $docx_path)) { $docx_dir = realpath('../cht-system/views/information/word_source'); + //图片及html目录 $img_dir = $docx_dir.'/'.$md5_file; - @mkdir($img_dir, 0700); - $html_parh = $img_dir.'/'.$md5_name; + is_dir($img_dir) || mkdir($img_dir, 0777); + //临时html文件 + $docx_parh = $img_dir.'/'.$md5_name; + $html_parh = str_ireplace('.docx', '.html', $docx_parh); //运行docx转化插件 - $command = 'C:\Users\cht77\AppData\Local\Yarn\bin\mammoth '.$path.' --output-dir='.$img_dir; + if ($_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '202.103.68.62') { + $yarnbin = 'C:\Users\cht77\AppData\Local\Yarn\bin\mammoth '; + $test_host = '//202.103.68.62:9096'; + } else { + $yarnbin = 'C:\Users\lmr\AppData\Local\Yarn\mammoth '; + $test_host = ''; + } + $command = $yarnbin.$docx_path.' --output-dir='.$img_dir; exec($command, $rs); - $html = file_get_contents(str_ireplace('.docx', '.html', $html_parh)); - //图片前缀 - //$html = str_ireplace($img_dir, '//202.103.68.62:9096/information-view/information/word_source', $html); + //图片处理 + $scan_img = scandir($img_dir); + $tmp = ''; + foreach($scan_img as $f) { + $tmp_ext = mb_strtolower(strrchr($f, '.')); + if ($tmp_ext == '.jpeg') { + $tmp_img = $img_dir.'/'.$f; + $tmp_jpg = str_ireplace('.jpeg', '.jpg', $tmp_img); + $im = imagecreatefromjpeg($tmp_img); + imagejpeg($im, $tmp_jpg); + imagedestroy($im); + //删除临时图片 + @unlink($tmp_img); + //$tmp .= $f . ' > '; + } + } + //html处理 + $html = file_get_contents($html_parh); + $html = preg_replace('/src="([\d]+).jpeg"/i', 'src="'.$test_host.'/information-view/information/word_source/'.$md5_file.'/$1.jpg"', $html); + //删除临时html + @unlink($html_parh); if ($html) { echo(json_encode(array( 'status' => 'success', - 'path' => $path, + 'path' => $docx_path, 'html' => $html ))); }