Uploading files

Darrell news at dorb.com
Tue Jun 29 10:11:07 EDT 1999


Jostein Søiland <jso at boxer.no.---> wrote in message
news:377874C6.6941CCFF at boxer.no.---...
> Hi, I'm writing a script that needs to upload files from the user's
> machine to a server, and it's used in combination with a form and
> HTML-file that lies on the server side. I wrote a piece of code that I
> thought would work, but it turned out that when i specify c:\foo.exe, it
> is the file on the server side that is uploaded and not the foo.exe on
> the client side. Evidently since the script is run on the server side.
>
> So my question is: How do I specify that it is the client's c:\foo.exe
> and not the server file that gets uploaded?
>
>
> Thanks
>
> Jostein Søiland
>

html>
<form name="Attachments" ENCTYPE="multipart/form-data" method="post"
action="http://www.xxx/cgibin/run.cgi/upload" >
<input type=file name=photo size=20 accept="image/*">
<input type=submit>
</form>
</html>


I'm using bobo to read the response to the post that contains the file.
This is a cut up snippet of how I did that, you just need something to
accept the data and write it to disk.
My skill level in these matters is about a 1, so I'm sure you could do
better.

def upload(REQUEST, RESPONSE):
        """
        Get a new file from a user
        """
        name= REQUEST.form[fieldName].filename
        if name=='':
                return
        names= string.split(name,'\\')
        names = string.split(names[-1],'/')
        name=names[-1]
        name = string.split(name)
        name = string.join(name,'')

        global baseDir
        fp = open(baseDir+name,'wb')
        buf = REQUEST.form[fieldName].read()
        fp.write(buf)
        fp.close()


--
--Darrell






More information about the Python-list mailing list