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()
<form method="post" enctype="multipart/form-data" action="test">
<input name="upload" type="file" size="60" maxlength="100000">
<input type="Submit" value="Upload">
</form>
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)
{{extend 'layout.html'}}
<h1>Upload File</h1>
{{=form}}
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'))
in controller:
def index():import osform=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)
import os
filepath = os.path.join(request.folder, 'view', 'pictures', filename)
For the path, i just don't write my path but it works only when i used the all path (from C:/ to my folder pictures like "C:/Adrien/web2py/applications/myApp/view/pictures/", don't know how to write only "pictures/"). So if i can resolve this and find how to change the filename, it's good and my problem will be fix.
For SQLFORM.factory : i already have a form divided in many html table with an anchor for each table, and i don't know how to do the same thing with the factory.
Someone know how to fix the problem with the path and the filename ?