nginx日志:2013/08/13 11:24:10 [error] 600#0: *5125 lua tcp socket read timed out, client: 221.122.125.116, server: , request: "POST /lua HTTP/1.1", host: "服务器地址", referrer: "
http://localhost/project_zhazha/zhazha/index.php?r=test/index"
function getPost()
local chunk_size = 524288
local form, err = upload:new(chunk_size)
local s = {};
local t = {};
local contentType
local restbl = { field={}, files={} }
if not form then
--ngx.log(ngx.ERR, "failed to new upload: ", err)
--ngx.exit("500")
local json_text = '{"ret":0, "err":"0018", "errmsg":"上传图片失败'.. err .. '"}'
ngx.say( json_text )
return
end
form:set_timeout(0)
--[[
array(
array(
"Content-Disposition"=>"form-data; name="file1"; filename="qq.txt""
"Content-Type"=>"text/plain"
"body"=>1
)
array(
"Content-Disposition"=>"form-data; name="CustomerTel"
"body"=>"zhouquan"
)
)
--]]
while true do
local typ, res, err = form:read()
if not typ then
ngx.say("failed to read: ", err)
ngx.exit(500)
return
end
if typ == 'header' then
t[res[1]] = res[2];
--ngx.say('header>> '..res[1]..' : '..res[2])
end
if typ == 'body' then
--ngx.say('body>> '..res)
t.body = res
table.insert(s, t)
t = {}
end
if typ == "eof" then
break
end
end
for i, content in ipairs(s) do
local contentType = content['Content-Type'];
if contentType then
local _,_,name,filename = string.find(content['Content-Disposition'], 'form%-data; name="(.+)"; filename="(.*)"')
table.insert(restbl.files, {name=name, filename=filename, type=contentType, value=content.body})
else
if content['Content-Disposition']~=nil then
local _,_,name = string.find(content['Content-Disposition'], 'form%-data; name="(.+)"')
restbl.field[name] = content.body
end
end
end
return restbl;
end
这个是我上传文件的方法,你看下,哪里有问题了?