Johnny Morano
johnny.morano at vlaanderen.be
Thu Jun 6 10:37:45 EST 2002
On Thursday 06 June 2002 09:59, you wrote: > fileDaSalvare=open(salva_su,'w') > fileDaSalvare.write(form['file_costi'].value) > fileDaSalvare.close() > > but work only with text-file indeed .... change: fileDaSalvare=open(salva_su,'w') into fileDaSalvare=open(salva_su, 'wb') 'wb' stands for 'write binary' and this is required for non-textfiles in windows. take a look at the following script (i called it fileUpload.py): # fileUpload.py # from mod_python import util from mod_python import apache def form(): output = """ <html> <body> <form action="insert" method="post" enctype="multipart/form-data" name="form"> File: <input type="file" name="fileField"><br> <input type="submit"> </form> </body> </html> """ return output def insert(req): import string import os form = req.form uploadDir = '/tmp/' if(form.has_key('fileField')): fileData = form['fileField'].file.read() filePathName = uploadDir + form['fileField'].filename open(filePathName, 'wb').write(fileData) return '<html><body>file uploaded to '+filePathName+'</body></html>' else: return '<html><body>no file to upload</body></html>' this works... or should work.. well, it works on my pc ;-) hope this helps greetz -- Johnny Morano - Linux Consultant ___________________________________________________ Ministerie Vlaamse Gemeenschap | Koning Albert II-laan, 7 (610) 1210 Brussel | tel: 02/5531319 mail: johnny.morano at vlaanderen.be |
|