2012-06-27 54 views
1

我已經使用下面的代碼來保存打開的docx文件。在php中使用edraw保存ms word 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); 
    ?> 

該文件不保存,當我們在瀏覽器中改變。任何人都可以看到這個問題嗎?

+0

最後我有固定的JavaScript代碼行。 用戶在javascript函數下面三行以下。 OA1.HttpAddPostFile(「C:\ wamp \ www \ rte \ sample2.docx」); OA1.HttpAddPostOpenedFile(「sample2.docx」); 0121.HttpPost(「http://localhost/rte/actor2.php」); – Saifi

+0

很奇怪,因爲用JS你無法訪問電腦文件夾!安全限制。 –

回答

0

HttpAddPostFile只能從遠程網站添加文件。它適用於本地磁盤文件。

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

 
\t \t document.OA1.HttpAddPostOpenedFile (sFileName); //save as the same file format with the sFileName then upload 
 
\t \t //document.OA1.HttpAddPostOpenedFile (sFileName, 16); //save as docx file then upload 
 
\t \t //document.OA1.HttpAddPostOpenedFile (sFileName, 0); //save as doc file then upload 
 
\t \t //document.OA1.HttpAddPostOpenedFile (sFileName, -4143); //save as xls file then upload 
 
\t \t //document.OA1.HttpAddPostOpenedFile (sFileName, 51); //save as xlxs file then upload 
 
\t \t 
 
\t \t document.OA1.HttpPost("upload_weboffice.php"); 
 
\t \t if(document.OA1.GetErrorCode() == 0 || document.OA1.GetErrorCode() == 200) 
 
\t \t { \t \t 
 
\t \t \t var sPath = "Save successfully! You can download it at http://www.ocxt.com/demo/" + sFileName; 
 
\t \t \t window.alert(sPath); 
 
\t \t } 
 
\t \t else 
 
\t \t { 
 
\t \t \t 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."); 
 
\t \t } 
 
\t } 
 
\t else{ 
 
\t \t window.alert("Please open a document firstly!"); 
 
\t } 
 
} 
 

 

 
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) 
 
{ 
 
\t 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); 
 
?>

+0

請檢查這個[URL](http://stackoverflow.com/help)它將有助於提高您的內容質量 –

相關問題