2

I'm attempting to use Lua (Love2d to be exact) to download and upload files to and from my server. Downloading went quite smooth using luasocket's http.request, but I'm having a lot of trouble doing the same with uploading.

I've put a index.html and upload.php script on my website, copied from here. It can be accessed at here. (Link will be removed when problem is resolved.)

I now want Lua to, somehow, use that to upload files to my server, but my current code gives the following error: "Sorry, file already exists. only JPG, JPEG, PNG & GIF files area allowed. Sorry, your file was not uploaded."

My Lua code is the following:

http = require("socket.http")
ltn12 = require("ltn12")

local response_body = {}
local file = io.open("newfile.jpg")

http.request{
    url = "http://tjakka5.sorunome.de/Test/upload.php",
    method = "POST",
    headers = {
        ["Content-Type"] = "multipart/form-data",
    },
    source = ltn12.source.file(file),
    sink = ltn12.sink.table(response_body)
}
print(response_body[1])

0 Answers0