Problem while uploading a binary file using cgi module

DeepBleu DeepBleu at DeepBleu.org
Mon Feb 4 09:27:23 EST 2002


Wang
Please send the code indented next time.  You know, you may know it inside
out.  But poor readers like me do not know your intentions and indenting
makes it easier to read.

>
> elif form.has_key("filename"):
> item = form["filename"]
What are you trying to access by using item=form["filename"]?
try the following:
elif form.has_key("filename"):
    if len(form["filename"].value) > 0:    #Process if file is not an empty
file.
                                                          #byte value is
form["filename"].value
        fp=open('1.jpg','wb')    #you can also open this file in a defined
directory.
                                           # make sure to use os.sep such as
"/" if necessary
        # please note:  access Byte value of files with
form["filename"].value;
        #access file name itself using form["filename"].filename
        fp.write(form["filename"].value)
        fp.flush    #good to use under certain conditions.  check your
favourite python library doc
        fp.close()
DeepBleu





More information about the Python-list mailing list