我上传文件到php的服务器有问题。
这是我的代码testForm.php
$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$sta["status"] = "Success";
echo stripslashes(json_encode($sta));
}
在livecode中
put the text of field "pF" into pathFile
put urlEncode("file:"& pathFile) into tFile
put libUrlFormData("userfile",tFile) into tArgList
post tArgList to URL "http://localhost:9999/livecodeTestJson/testForm.php"
它不起作用。
答案 0 :(得分:1)
我不知道,如果你的php代码是正确的,但你的livecode部分不是。
要将文件发布到网络服务器,您需要libUrlMultipartFormData函数。
下面是libURL documentatin的样本。我使用你的值调整了一下
put empty into tFormData
put "http://www.someserver.com/cgi-bin/form.cgi" into tUrl
put the text of field "pF" into pathFile
put "<file>" & pathfile into tFile
if libUrlMultipartFormData(tFormData, "userfile", tFile) is not empty then
answer it ##error
else
set the httpHeaders to line 1 of tFormData
post line 2 to -1 of tFormData to url tUrl
## check the result, etc., here
set the httpHeaders to empty
end if
如果您还想要发布表单数据,则必须在libURLMultiPartFormData的调用中包含该数据。
假设您有表单字段“name”,“email”和“message”,变量tName,tEmail和tMessage包含数据,那么您将使用以下行替换示例脚本的第5行
if libUrlMultipartFormData(tFormData, "name", tName, "email", tEmail, "message", tMessage, "userfile", tFile) is not empty