【问题标题】:saving ms word docx file using edraw in php在 php 中使用 edraw 保存 ms word docx 文件
【发布时间】:2012-06-27 05:42:54
【问题描述】:

我使用以下代码保存打开的 docx 文件。

javascript:

function SavetoServer(){
    OA1.Save();
    OA1.CloseDoc();
    OA1.HttpInit();
    OA1.HttpAddPostFile("C:\wamp\www\rte\sample2.docx");
    document.OA1.HttpPost("http://localhost/rte/actor2.php");

}

php代码“actor2.php”

<?php
    header("http/1.1 200 OK");
    $handle = fopen($_FILES['trackdata']['name'],"w+");
    if($handle == FALSE)
    {
      exit("Create file error!");
    }
    $handle2 = fopen($_FILES['trackdata']['tmp_name'],"r");
    $data = fread($handle2,$_FILES['trackdata']['size']);
    fwrite($handle,$data);
    fclose($handle2);
    fclose($handle);
    exit(0);
  ?>

当我们在浏览器中更改时,文件没有保存。任何人都可以看到这个问题吗?

【问题讨论】:

  • 最后我修复了 javascript 代码行。在javascript函数中使用以下三行。 OA1.HttpAddPostFile("C:\wamp\www\rte\sample2.docx"); OA1.HttpAddPostOpenedFile("sample2.docx"); OA1.HttpPost("localhost/rte/actor2.php");
  • 奇怪,因为使用 JS 你无法访问计算机文件夹!安全限制。

标签: php file ms-word save docx


【解决方案1】:

HttpAddPostFile 只能添加来自远程网站的文件。它确实适用于本地磁盘文件。

function SavetoServer()
{
	if(document.OA1.IsOpened)
	{
		document.OA1.SetAppFocus();
		document.OA1.HttpInit();	
		var sFileName = document.OA1.GetDocumentName();

		document.OA1.HttpAddPostOpenedFile (sFileName); //save as the same file format with the sFileName then upload
		//document.OA1.HttpAddPostOpenedFile (sFileName, 16); //save as docx file then upload
		//document.OA1.HttpAddPostOpenedFile (sFileName, 0); //save as doc file then upload
		//document.OA1.HttpAddPostOpenedFile (sFileName, -4143); //save as xls file then upload
		//document.OA1.HttpAddPostOpenedFile (sFileName, 51); //save as xlxs file then upload
		
		document.OA1.HttpPost("upload_weboffice.php");
		if(document.OA1.GetErrorCode() == 0 || document.OA1.GetErrorCode() == 200)
		{		
			var sPath = "Save successfully! You can download it at http://www.ocxt.com/demo/" + sFileName;
			window.alert(sPath);
		}
		else
		{
			window.alert("you need enable the IIS Windows Anonymous Authentication if you have not set the username and password in the HttpPost method. you need set the timeout and largefile size in the web.config file.");
		}
	}
	else{
		window.alert("Please open a document firstly!");
	}
}


upload_weboffice.php

<?php

$sql = sprintf("username=%s  passwd=%s  param=%s", $_POST['user'],$_POST['password'],$_POST['param']);
echo $sql;

$filecount = count($_FILES["trackdata"]["name"]);
echo "\r\n";
echo "file account:";
echo $filecount;
echo "\r\n";

$sql = sprintf("file=%s  size=%s error=%s tmp=%s", $_FILES['trackdata']['name'],$_FILES['trackdata']['size'],$_FILES['trackdata']['error'],$_FILES['trackdata']['tmp_name']);
echo $sql;
echo "\r\n";

$filen = $_FILES['trackdata']['name'];
//$filen = iconv("UTF-8", "GBK", $filen);
$handle = fopen($filen,"w+");
if($handle == FALSE)
{
	exit("Create file error!");
}

$handle2 = fopen($_FILES['trackdata']['tmp_name'],"r");
$data = fread($handle2,$_FILES['trackdata']['size']);
echo $data;

//file_put_contents($handle, "\xEF\xBB\xBF".  $data);
//fwrite($handle,pack("CCC",0xef,0xbb,0xbf));
fwrite($handle,$data);

fclose($handle2);
fclose($handle);


exit(0);
?> 

【讨论】:

  • 请查看URL,这将有助于提高您的内容质量
猜你喜欢
  • 2014-01-08
  • 2020-03-24
  • 2023-04-07
  • 2017-10-09
  • 2012-08-16
  • 2020-04-10
  • 1970-01-01
  • 1970-01-01
  • 2019-02-01
相关资源
最近更新 更多