Upload script

Greg Hotson ghotsong at bigpond.com
Sun Feb 16 02:34:55 CET 2003


"Rene Pijlman" <reageer.in at de.nieuwsgroep> wrote in message
news:gsip4vssatpgmk4dkgrf00f4mvb1blthkg at 4ax.com...
> Lois Hotson:
> >I made a cgi 'upload script' so that I can upload files to my server via
the
> >web. It seems to work perfectly for ASCII files but binary files dont
work
> >at all (They make python freeze).
>
> We'll need to see the actual source code to be able to locate
> the problem.
>
> >Has anyone had any problems with this kind of thing before?
>
> Yes, by not opening a binary file as binary.
>
> --
> René Pijlman
>
> Wat wil jij leren?  http://www.leren.nl

Sorry that I wasn't very specific.
Here's the script source code:

import os,cgi
path = r'C:\path\to\upload'
form = cgi.FieldStorage()
if form.has_key("userfile"):
        item = form["userfile"]
        if item.filename:
            data=item.file.read()
            upfile =file(path + '/' +os.path.split(item.filename)[1],'wb')
            upfile.write(data)
            upfile.close()

and heres the form html:

<form method="POST" action="index.py" encType="multipart/form-data">
<input type="file" name="userfile">
<input type="submit" value="Submit">
</form>








More information about the Python-list mailing list