0

我正在尝试将文档文件从 Lotus Script 发送到 Web 服务器并将其保存在那里。不幸的是,文件传输不起作用。我有一个 Lotusscript 代理来获取文档,这部分工作正常( str_filecontent 包含正确的 xml 文件),但文件传输或保存不起作用。这是我的 Lotusscript 代理:

Option Public
Option Declare

Sub Initialize
    'Declare long
    Dim lng_resolveTimeout, lng_connectTimeout, lng_sendTimeout, lng_receiveTimeout As Long

    'Declare integer
    Dim int_serverCredentials As Integer

    'Declare variants
    Dim var_submitObject As Variant

    'Set values
    int_serverCredentials = 0

    lng_resolveTimeout = 120000 'miliseconds = 2 minutes
    lng_connectTimeout = 1200000
    lng_sendTimeout = 1200000
    lng_receiveTimeout = 1200000

    'Create HTTP object
    Set var_submitObject = CreateObject("WinHTTP.WinHTTPRequest.5.1")
    Call var_submitObject.SetTimeouts(lng_resolveTimeout, lng_connectTimeout, lng_sendTimeout, lng_receiveTimeout)

    'Standards for this post
    %REM
Content-Type: multipart/form-data; boundary={boundary}
{boundary}
Content-Disposition: form-data; name="data"; filename="{filename}"
Content-Type: text/plain
{contents}
{boundary}--
    %END REM
    Dim str_url As String
    str_url = "http://.../upload.php"
    Dim str_AUTH As String
    Dim str_boundary As String
    Dim str_filecontent As String

    str_filecontent = get_data()
    Dim submitHTTP
    'Set post parameters
    Call var_submitObject.open("POST", str_url, False)
    Call var_submitObject.setRequestHeader("Accept", "application/xml")
    Call var_submitObject.setRequestHeader("Authorization", "Basic " & str_auth)
    Call var_submitObject.setRequestHeader("Content-Type", "multipart/form-data; boundary=b1")
    str_boundary = |--b1| & Chr(13) & Chr(10) &_
|Content-Disposition: form-data; name="data"; filename="name.txt"| & Chr(13) & Chr(10) &_
|Content-Type: text/plain| & Chr(13) & Chr(10) &_
    str_fileContent & |b1--|
    'Send the HTTP request
    Call var_submitObject.Send(str_boundary)
    'Wait for the answer and set object as returned value for further validation
    Call var_submitObject.WaitForResponse
    Set submitHTTP = var_submitObject
    'Clear memory
    Set var_submitObject = Nothing
End Sub

%REM
    Function get_data
    Description: Comments for Function
%END REM
Function get_data() As String
    Dim session As New NotesSession
    Dim doc As NotesDocument
'   Dim db As NotesDatabase
    Dim exporter As NotesDXLExporter
'   Set db = session.CurrentDatabase
    Dim workspace As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Set uidoc = workspace.CurrentDocument
    Set doc = uidoc.Document
'   Set doc = SESSION.CU
    Set exporter = session.CreateDXLExporter
    get_data = exporter.Export(doc)
    Print get_data
End Function

这是我的 web 服务器 PHP 来接收和保存文件:

<?php

define("UPLOAD_DIR", "/temp/");

if (!empty($_FILES["data"])) {
    $myFile = $_FILES["data"];

    if ($myFile["error"] !== UPLOAD_ERR_OK) {
        echo "<p>An error occurred.</p>";
        exit;
    }

    // preserve file from temporary directory
    $success = move_uploaded_file($myFile["tmp_name"],
        UPLOAD_DIR . $name);
    if (!$success) {
        echo "<p>Unable to save file.</p>";
        exit;
    }

    // set proper permissions on the new file
    chmod(UPLOAD_DIR . $name, 0644);
}
?>

谢谢你的时间!

4

0 回答 0