On Wednesday, December 16, 2015 at 4:07:11 AM UTC-5, Adrien wrote:
>
>
> 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 that code, "path/" is just an example. You must provide an actual 
filesystem path where you want to store the file. Also, in order to prevent 
a directory traversal attack, you would want to either rename the file 
(e.g., via base 16 encoding, as the DAL does with upload fields) or check 
to make sure the final absolute path is not outside your base upload folder.

Anthony

-- 
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.

Reply via email to