Lotusscript:在 PHP 中将文件从电子邮件发送到网站时出现问题
Lotusscript: Issue sending a file from an email to a website in PHP
我想通过 lotusscript 代理将文件从我当前的电子邮件发送到我的网站。我想做这样的事情:(我知道这段代码行不通,但它是为了展示这个想法)
Sub Initialize
On Error GoTo ErrorHandler
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim item As Variant
Dim uidoc As NotesUIDocument
Dim CurrentDocColl As NotesDocumentCollection
Dim url As String
Dim jsonBody As String
Dim http As NotesHTTPRequest
Dim headers As Variant
Dim ret As Variant
Set Session = New NotesSession
Set db = Session.Currentdatabase
Set CurrentDocColl = db.Unprocesseddocuments
Set doc = CurrentDocColl.Getfirstdocument
While Not doc Is Nothing
Set item = doc.GETFIRSTITEM("Body")
If doc.HasEmbedded Then
url="http://myurl.com/addFiles.php"
jsonBody="value={""id"":""7777"",""file"":"""+item.EmbeddedObjects+"""}"
Set http=session.CreateHTTPRequest()
http.preferstrings = True
Call http.SetHeaderField("ContentType","application/json")
ret = http.Post(url, jsonBody)
MessageBox ret
End If
Set doc=CurrentDocColl.Getnextdocument(doc)
Wend
Exit Sub
ErrorHandler:
MessageBox "Erreur N° : " +Cstr(Err)_ ' code numérique de l'erreur
+" Description : " + Error(Err)_ ' La description de l'erreur
+ " Ligne N° : "+ CStr(Erl)_ ' La ligne où se trouve l'erreur
+"",16, " ERREUR !"
Exit Sub
End Sub
这是我的 php 检索文件的代码:
header("Vary: Origin");
header("Content-type: application/json");
if (isset($_FILES['file'])) {
$total = count($_FILES['file']['name']);
for ($i = 0; $i < $total; $i++) {
$tmpFileName = $_FILES['file']['tmp_name'][$i];
echo $tmpFileName;
}
}
如何将他的文件发送到我的网站?因为通常在 Javascript 中,当我们想要将文件发送到 PHP 代码时,我们将其发送到包含“文件”类型字段的 FormData 中。但我不知道 lotusscript 中的等价物。我对如何执行此操作感到有些困惑。
感谢您的帮助!
您将需要使用ExtractFile method of the NotesEmbeddedObject class将附件数据保存到一个文件中,然后您将需要读取该文件的内容并将其放入它进入您为 POST 数据发送的变量。据我所知,一步完成此操作没有捷径可走。我使用这种技术已经有好几年了,它是在 Java 代码中而不是在 LotusScript 中。请注意,您的代码必须具有在代码为 运行.
的服务器或客户端上创建文件的权限
我想通过 lotusscript 代理将文件从我当前的电子邮件发送到我的网站。我想做这样的事情:(我知道这段代码行不通,但它是为了展示这个想法)
Sub Initialize
On Error GoTo ErrorHandler
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim item As Variant
Dim uidoc As NotesUIDocument
Dim CurrentDocColl As NotesDocumentCollection
Dim url As String
Dim jsonBody As String
Dim http As NotesHTTPRequest
Dim headers As Variant
Dim ret As Variant
Set Session = New NotesSession
Set db = Session.Currentdatabase
Set CurrentDocColl = db.Unprocesseddocuments
Set doc = CurrentDocColl.Getfirstdocument
While Not doc Is Nothing
Set item = doc.GETFIRSTITEM("Body")
If doc.HasEmbedded Then
url="http://myurl.com/addFiles.php"
jsonBody="value={""id"":""7777"",""file"":"""+item.EmbeddedObjects+"""}"
Set http=session.CreateHTTPRequest()
http.preferstrings = True
Call http.SetHeaderField("ContentType","application/json")
ret = http.Post(url, jsonBody)
MessageBox ret
End If
Set doc=CurrentDocColl.Getnextdocument(doc)
Wend
Exit Sub
ErrorHandler:
MessageBox "Erreur N° : " +Cstr(Err)_ ' code numérique de l'erreur
+" Description : " + Error(Err)_ ' La description de l'erreur
+ " Ligne N° : "+ CStr(Erl)_ ' La ligne où se trouve l'erreur
+"",16, " ERREUR !"
Exit Sub
End Sub
这是我的 php 检索文件的代码:
header("Vary: Origin");
header("Content-type: application/json");
if (isset($_FILES['file'])) {
$total = count($_FILES['file']['name']);
for ($i = 0; $i < $total; $i++) {
$tmpFileName = $_FILES['file']['tmp_name'][$i];
echo $tmpFileName;
}
}
如何将他的文件发送到我的网站?因为通常在 Javascript 中,当我们想要将文件发送到 PHP 代码时,我们将其发送到包含“文件”类型字段的 FormData 中。但我不知道 lotusscript 中的等价物。我对如何执行此操作感到有些困惑。 感谢您的帮助!
您将需要使用ExtractFile method of the NotesEmbeddedObject class将附件数据保存到一个文件中,然后您将需要读取该文件的内容并将其放入它进入您为 POST 数据发送的变量。据我所知,一步完成此操作没有捷径可走。我使用这种技术已经有好几年了,它是在 Java 代码中而不是在 LotusScript 中。请注意,您的代码必须具有在代码为 运行.
的服务器或客户端上创建文件的权限