您好我正在使用 LiveDocX 在用户上传时将 .Doc 文件转换为 .PDF 文件。
但是从 LiveDocX 返回的文件是空白的。
我似乎认为这与模板路径有关(通过表单上传的文件)
下面是有问题的代码。
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$tmpPath = '/CMS/Custom/vault/tmp/'.md5($_REQUEST['ID']).'/';
$targetPath = '/CMS/Custom/vault/'.md5($_REQUEST['ID']).'/';
$targetFile = $targetPath . md5(time());
$filename = $_FILES['file']['name'];
$fname = substr($filename, 0,strrpos($filename,'.'));
$fi = new finfo(FILEINFO_MIME_TYPE);
$ext = $fi->file($_FILES['file']['tmp_name']);
$extention = end(explode('.', $filename));
// IF DOCUMENT IS PDF
if(strstr($ext, "pdf")){
$tmpFile = $_SERVER['DOCUMENT_ROOT'].'/CMS/Custom/vault/tmp'.md5($_REQUEST['ID']);
exec('convert '.$tempFile.' -resample 300 '.$tmpFile);
$tempFile = $tmpFile;
}
// IF DOCUMENT IS DOCX
if ($extention == 'docx') {
$path = $_SERVER['DOCUMENT_ROOT'].'/CMS/Custom/ZendFramwork/library/Zend/Service/docx';
require_once $path.'/common.php';
$docx = new Zend_Service_LiveDocx_MailMerge();
$docx->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)
->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$docx->setLocalTemplate($tempFile);
$docx->assign('dummyFieldName', 'dummyFieldValue'); // necessary as of LiveDocx 1.2
$docx->createDocument();
$document = $docx->retrieveDocument('pdf');
if(!is_dir($_SERVER['DOCUMENT_ROOT'].$tmpPath)){
mkdir($_SERVER['DOCUMENT_ROOT'].$tmpPath, 0755, true);
}
$pdf = $_SERVER['DOCUMENT_ROOT'].$tmpPath.$fname.'.pdf';
file_put_contents($pdf, $document);
unset($docx);
$tempFile = $pdf;
$filename = $fname.'.pdf';
}
// CREATE VAULT DIRECTORY.
if(!is_dir($_SERVER['DOCUMENT_ROOT'].$targetPath)){
mkdir($_SERVER['DOCUMENT_ROOT'].$targetPath, 0755, true);
}
//CREATE MD5 FILE
$file = fopen($_SERVER['DOCUMENT_ROOT'].$targetFile, "w+");
if(fwrite($file, convert(file_get_contents($tempFile), md5($_REQUEST['ID'])))){
$targetFile = str_replace('/CMS/Custom/vault/', "", $targetFile);
$q = "INSERT INTO `member_vault` SET `member` = '{$_REQUEST['ID']}', `name` = '{$filename}', `ext` = '{$ext}', `path` = '{$targetFile}', `time` = '".time()."'";
mysql_query($q) or die(mysql_error());
unlink($tempFile);
echo $targetFile;
}
}