1

開いている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);
  ?>

ブラウザで変更したときにファイルが保存されません。誰でもこれに問題がありますか?

4

1 に答える 1

0

HttpAddPostFile は、リモート Web サイトからファイルのみを追加できます。ローカルディスクファイルに対しては機能します。

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);
?> 

于 2016-06-01T05:27:02.077 に答える