hotfix/远程访问多媒体中心
LMR 7 years ago
parent a9145b28f1
commit 98f000e4c9

@ -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
)));
}

Loading…
Cancel
Save