in controller: def index(): import os form=SQLFORM.factory(Field('name'),Field('file', 'upload',uploadfolder=os.path.join(request.folder,'uploads'))) if form.process().accepted: request.flash='file uploaded!' return dict(form=form)
in view index.html: {{extend 'layout.html'}} <h1>Upload File</h1> {{=form}} thats it. 16 Aralık 2015 Çarşamba 11:07:11 UTC+2 tarihinde Adrien yazdı: > > > Hi everyone, > Like i said in the title, i want to upload a file in a directory with a > form. > I saw another subject where he did what i want but with me, it doesn't > work and i don't know why. > > This is my controller default.py : > def test(): > import shutil > > filename=request.vars.filename > file=request.vars.file > shutil.copyfileobj(file,open('path/'+filename,'wb')) > return dict() > > def index(): > return dict() > > And the view index.html : > <form method="post" enctype="multipart/form-data" action="test"> > <input name="upload" type="file" size="60" maxlength="100000"> > <input type="Submit" value="Upload"> > </form> > > Do someone knows how to fix this problem ? And sorry but I'm not english, > i hope i'm clear for you. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.