php linux下保存文件路径怎么写,linux下php导入带图片的word文档转为html,图片保存下来生成路径。...
linux下yum install libreoffice
yum install libreoffice-headless
如果出現(xiàn)異常,在頁面上不一定表現(xiàn)出來,而是頁面卡著一直沒響應(yīng),通過apache日志看到相關(guān)錯誤[Java framework] Error in function createSettingsDocument (elements.cxx).
javaldx failed!
Warning: failed to read path from javaldx
處理為#因?yàn)橛脩?www沒有HOME 會跑到root導(dǎo)致沒權(quán)限,可指定 export HOME=/tmp/ && 解決$shell = "export HOME=/tmp/ && /usr/bin/libreoffice --headless --convert-to html --print-to-file --printer-name nasty_lowres_printer --outdir {$_SERVER['DOCUMENT_ROOT']}/out_file/ {$full_result_path} > /dev/null 2>/dev/null &";
php如果做了函數(shù)安全過濾,需要放行shell_exec
php代碼public function upload(){
if(IS_POST){
header('Content-type: text/html; charset=UTF-8');
$reulst = upload('file');
//如果成功上傳doc,轉(zhuǎn)html
$full_result_path = $_SERVER['DOCUMENT_ROOT'].$reulst;
if(file_exists($full_result_path)){
$shell = "/usr/bin/libreoffice --headless --convert-to html --print-to-file --printer-name nasty_lowres_printer --outdir {$_SERVER['DOCUMENT_ROOT']}/out_file/ {$full_result_path}";
$doc_file_contents = shell_exec($shell);
$pattern = '/\/(\d+).html/';
preg_match_all($pattern,$doc_file_contents,$match);
if(!empty($match[0])){
$path = ($_SERVER['DOCUMENT_ROOT'].'/out_file'.$match[0][0]);
$html = file_get_contents($path);
$img_pattern = '/
preg_match_all($img_pattern,$html,$match2);
$base64_arr = $match2[2];
set_time_limit(120);
$Qiniu = new Qiniu('xxxxx','xxxxx','xxxxx');
//七牛日志
$log = [];
foreach($base64_arr as $base64){
if(strlen($base64) < 60){
$html = str_replace($base64,'',$html);
$html = preg_replace('/]*)>/i','',$html);
}else{
preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64, $ext_result);
$file_name = date('YmdHis').'.'. rand(10000, 99999).'.'.$ext_result[2];
$qiniukey= date("Ymd").'/doc/'.$file_name;
$status = $Qiniu->upload_file($base64,$qiniukey);
array_push($log,json_encode($status));
if($status['status']=='success'){
$status = 'http://cms3.jmcdn.cn/'.$status['key'];
$html = str_replace($base64,$status,$html);
}else{
//如果七牛保存失敗,則保存到本地 [by shw 20180709反復(fù)測試,有時候會傳七牛失敗 ,但最后幾次均全部成功,可能和網(wǎng)絡(luò)有關(guān)
//也可能文件名,測試也是加了隨機(jī)數(shù)文件名之后,確認(rèn)下,如果還有問題則需要在這里還需要傳一次到網(wǎng)上,本地圖片無法主站下圖]
$new_file = "{$_SERVER['DOCUMENT_ROOT']}/out_file/".$file_name;
file_put_contents($new_file, base64_decode(str_replace($ext_result[1], '', $base64)));
$html = str_replace($base64,"/out_file/".$file_name,$html);
}
}
}$html = removeFormat($html);
echo $html;
print_r($log);die();
}else{
die('no match');
}
}else{
echo '沒有轉(zhuǎn)換文件,輸出 '.$reulst;
}
die();
}
$this->display();
}
html頁面
upload的視圖
上傳文件function sub() {
var obj = new XMLHttpRequest();
obj.onreadystatechange = function() {
if (obj.status == 200 && obj.readyState == 4) {
var result = obj.responseText;
if(result.indexOf("upload") >-1 && result.indexOf("image") >-1){
window.opener.document.getElementById("message").innerHTML = result;
document.getElementById('con').innerHTML = "上傳成功";
document.getElementById("a1").style.display = "none";
document.getElementById("a2").style.display = "block";
}else{
document.getElementById('con').innerHTML = result;
}
}
}
// 通過Ajax對象的upload屬性的onprogress事件感知當(dāng)前文件上傳狀態(tài)
obj.upload.onprogress = function(evt) {
// 上傳附件大小的百分比
var per = Math.floor((evt.loaded / evt.total) * 100) + "%";
// 當(dāng)上傳文件時顯示進(jìn)度條
document.getElementById('parent').style.display = 'block';
// 通過上傳百分比設(shè)置進(jìn)度條樣式的寬度
document.getElementById('son').style.width = per;
// 在進(jìn)度條上顯示上傳的進(jìn)度值
document.getElementById('son').innerHTML = per;
}
// 通過FormData收集零散的文件上傳信息
var fm = document.getElementById('userfile3').files[0];
var fd = new FormData();
fd.append('userfile', fm);
obj.open("post", "/index.php?g=portal&m=shw&a=upload");
obj.send(fd);
}
#parent {
width: 200px;
height: 20px;
border: 2px solid gray;
background: lightgray;
display: none;
}
#son {
width: 0;
height: 100%;
background: lightgreen;
text-align: center;
}
圖片上傳
html頁面調(diào)用者
Titlefunction upload(){
window.open("/index.php?g=portal&m=shw&a=upload","上傳文檔","width=500,height=480,screenX=400,screenY=100");
}
非特殊說明,本博所有文章均為博主原創(chuàng)。
最新文章
總結(jié)
以上是生活随笔為你收集整理的php linux下保存文件路径怎么写,linux下php导入带图片的word文档转为html,图片保存下来生成路径。...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牙齿黑色洗牙能洗掉吗
- 下一篇: 牙齿贴面有什么危害吗