Hi, I need to upload a file using http.request, I had it working with network.request but realised that synchronous data was more suited to the task. I have done a lot of searching over the last 2 days but cannot seem to figure out what my problem is. I have checked the php settings on my server and everything is OK there. I am not recieving any error messages back from the server, but it appears that $_file is empty so I assume the error is in the lua file.
Thanks in advance.
Here is my code.
database.lua
function uploadPhoto ( filename )
print("Upload Photo Top")
local mime = require "mime"
local path = system.pathForFile( filename, system.DocumentsDirectory)
URL = "http://www.myserver.com/uploadImage.php"
local fileHandle = io.open( path)
local len = fileHandle:seek( "end", 0 )
io.close(fileHandle)
print("len=" .. len)
if fileHandle then
print("Image Found!")
response\_body = {}
local body, code, headers = http.request{
url = URL ,
method = "POST",
headers = {
["Content-Type"] = "multipart/form-data",
["Content-Length"] = len
},
source = ltn12.source.file("newimage.jpg"),
sink = ltn12.sink.table(response\_body)
}
print("Body = ", body)
print("code = ", code)
print("headers = ", headers[1])
print("response body = ", response\_body[1])
else
print("Image Not Found")
end
end
uploadImage.php
[code]
<?php// In PHP versions earlier than 4.1.0, $HTTP\_POST\_FILES should be used instead // of $\_FILES. $uploaddir = '/files/'; $uploadfile = $uploaddir . basename($\_FILES['userfile']['name']); echo ' '; if (move\_uploaded\_file($\_FILES['userfile']['tmp\_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } echo "Temp filename = " . $\_FILES['userfile']['tmp\_name'] ; echo '\nHere is some more debugging info:'; print\_r($\_FILES); print " "; ?\> [/code] [import]uid: 184705 topic\_id: 34640 reply\_id: 334640[/import]