News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
LuaSocket image
Author Message
asafp
Member
***


Posts: 81
Group: Registered
Joined: Jan 2008
Status: Offline
Reputation: 0
Post: #1
RE: LuaSocket image

Code:
function GetFile(urlin,headin,redirin,fid)
local http=require('socket.http')
local url=require('socket.url')
local ltn12 = require("ltn12")
local mime = require("mime")
local urlname=urlin
local headers={}
local redir=true
if redirin==false then
    redir=false
end
if headin==nil then
    headers = {["Useragent"]='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11',
--             ["Content-Type"] =  "application/x-www-form-urlencoded",
--             ["Timeout"] = "1",
            ["Accept-Encoding"]="gzip,deflate",
             ["Connection"]="Keep-Alive"}
else
    headers=headin
end
local t={}
local r, c, h, w = http.request {
  method = "GET",
  headers=headers,
  url = urlname,
  redirect = redir,
--  sink = ltn12.sink.table(t)
  sink = ltn12.sink.file(fid)
}
return c, h
end
imgin='Lg638183-01.jpg'
imgurl='http://www.compucars.co.uk/carpics/'..imgin
filename='img_compucars/'..imgin
fh=io.open(filename,'w')
c=nil
status=nil
c, heads=GetFile(imgurl, nil, nil, fh)
print (c)


Here you go.

07-26-2008 12:54 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
LuaSocket image - asafp - 07-25-2008, 09:52 AM
RE: LuaSocket image - znarf - 07-25-2008, 08:39 PM
RE: LuaSocket image - asafp - 07-26-2008, 12:07 AM
RE: LuaSocket image - JohnMurga - 07-26-2008, 05:49 AM
RE: LuaSocket image - asafp - 07-26-2008 12:54 PM
RE: LuaSocket image - asafp - 07-31-2008, 07:01 AM
RE: LuaSocket image - JohnMurga - 07-31-2008, 08:52 PM
RE: LuaSocket image - asafp - 08-01-2008, 02:31 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: