Re: sample file upload
"maxsimon1980" <[email protected]> Mon, 11 Aug 2008 09:56:48 -0000
| Newsgroups | gmane.text.clearsilver.general |
|---|---|
| Message-ID | <[email protected]> |
Thanks for your response, but i dont want to use python or any other script. I can use clearsilver C API with cgi application .i just want to know whether it is possible or not.If any one have a sample application please upload Regards Max --- In [email protected], Brandon Long <blong@...> wrote: > > Do you have a perferred language? > > Attached is a test python one I had lying around. upload.py is a dirt > simple one, upload2.py uses a callback so you get information as the > uplaod is going on. > > Brandon > > On 08/08/08 maxsimon1980 uttered the following other thing: > > hello every one, > > > > can anyone send me a sample code for file up load. > > please send me the code for cgi and html part. > > > > Regards > > Max > > > > > > ------------------------------------ > > > > Yahoo! Groups Links > > > > > > > -- > "A fundamental law: no matter how good you are, someone somewhere > believes that you're going to Hell." -- Andrew C. Bulhak > http://www.fiction.net/blong/ > > #!/usr/local/bin/python2.2 > import neo_cgi > import sys, os > import traceback > > def exceptionString(): > import StringIO > > ## get the traceback message > sfp = StringIO.StringIO() > traceback.print_exc(file=sfp) > exception = sfp.getvalue() > sfp.close() > > return exception > > class Page: > def __init__(self): > self.ncgi = neo_cgi.CGI() > self.ncgi.setUploadCB(None, self.upload_cb) > try: > os.unlink('/tmp/cstest.txt') > except os.error: > pass > try: > os.unlink('/tmp/file') > except os.error: > pass > self.ncgi.parse() > > def upload_cb(self, foo, nread, length): > f = open('/tmp/cstest.txt', 'a') > f.write("Uploaded %d out of %d\n" % (nread, length)) > f.close() > return 0 > > def display(self, file): > if self.ncgi.hdf.getValue("Query.file", ""): > try: > fp = self.ncgi.filehandle("file") > data = fp.read() > f = open("/tmp/file", "w") > f.write(data) > > except neo_cgi.CGIFinished: > return > except Exception, Reason: > sys.stderr.write("Python Exception: %s\n" % (str(repr(Reason)))) > s = neo_cgi.text2html("Python Exception: %s" % exceptionString()) > self.ncgi.error(s) > self.ncgi.display(file) > sys.stdout.write('<pre>%s</pre>' % > neo_cgi.htmlEscape(self.ncgi.hdf.dump())) > > p = Page() > p.display("hello.cst") > > <html> > <title>Test upload</title> > <body> > <form name=upload method=POST enctype="multipart/form-data"> > <input type=file name=file> > <input type=submit name=Action.Upload value="Upload"> > </body> > </html> > > #!/usr/bin/env python > > import sys, os, traceback, string > import neo_cgi > > def log (s): > sys.stderr.write("CGI: %s\n" % s) > > def exceptionString(): > import StringIO > > ## get the traceback message > sfp = StringIO.StringIO() > traceback.print_exc(file=sfp) > exception = sfp.getvalue() > sfp.close() > > return exception > > def main (argv, environ): > # log ("starting") > cgi = neo_cgi.CGI("") > > try: > fp = cgi.filehandle("file") > print "Content-Type: text/plain\r\n\r\n" > data = fp.read() > print data > > f = open("/tmp/file", "w") > f.write(data) > > except neo_cgi.CGIFinished: > return > except Exception, Reason: > log ("Python Exception: %s" % (str(repr(Reason)))) > s = neo_cgi.text2html("Python Exception: %s" % exceptionString()) > cgi.error (s) > > if __name__ == "__main__": > main (sys.argv, os.environ) >