@daniel: I have index class to handle POST request.
class index:
def GET(self):
return render.index()
def POST(self):
temp = web.input(myfile={})
filedir = '/home/daidq/web.py/upload/images'
if 'myfile' in temp:
filepath = temp.myfile.filename.replace('\\','/')
filename = filepath.split('/')[-1]
fout = open(filedir +'/'+ filename,'w')
fout.write(temp.myfile.file.read())
fout.close()
raise web.seeother('/gallery')
On Thursday, June 6, 2013 11:15:12 AM UTC+7, Joseph Do wrote:
>
> I am trying to upload images and here is my code for handling file upload:
>
> def POST(self):
>> temp = web.input(myfile={})
>> filedir = '/home/daidq/web.py/upload/images'
>> if 'myfile' in temp:
>> filepath = temp.myfile.filename.replace('\\','/')
>> filename = filepath.split('/')[-1]
>> fout = open(filedir +'/'+ filename,'w')
>> fout.write(temp.myfile.file.read())
>> fout.close()
>> raise web.seeother('/gallery')
>>
>
> But the problem is that it keeps show me error: *name 'temp' is not
> defined* at *if 'myfile' in temp:* line
>
> Please help me to get over this.
>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.