|
Simon
simonrolin at gmail.com
Wed Nov 21 14:39:48 EST 2007
Hi all of you,
I'm new to modpython and I'm actually facing some problem when trying to
upload file.... I've read a lot but have not found any answer...
Here is my HTML of my form:
<form action=Upload2.py method=Post enctype="mutlipart/form-data">
<input type="file" name="file" value=""><div class="button"><input
type="submit" name="submit" value="Rechercher" class="submit"
/></div></form>
and here is Upload2 function:
def Upload2(req):
timer = ExecTime()
_session(req)
myPage = page.Page(req,"Ajouter une photo")
fileitem = req.form['file']
myPage.add("Type is :" + str(type(fileitem)) + "<br />")
if fileitem.filename:
import os
# strip leading path from file name to avoid directory traversal
attacks
fname = os.path.basename(fileitem.filename)
# build absolute path to files directory
dir_path = os.path.join(os.path.dirname(req.filename), 'files')
open(os.path.join(dir_path, fname), 'wb').write(fileitem.file.read
())
myPage.add("The file" + fname)
else:
myPage.add('No file was uploaded')
myPage.add(str(req.form))
myPage.execTime = timer.stop()
myPage.send()
myPage being a class to generate the page....
and here is the result...:
Type is :
No file was uploaded{'submit': [Field('submit', 'Rechercher')], 'file':
[Field('file', '08 - Big Furry Head.m4a')]}
Does someone have any idea of what's going wrong????
It would be really great because it's actually 4 day's I'm trying to find an
answer but without any succes...
I promise you I'have really search a lot before sending you this email....
Thanks a lot for your answers!
Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20071121/49970fbb/attachment.html
|