maxsimon1980 | 8 Aug 2008 13:25
Picon
Favicon

sample file upload

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

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Ads on Yahoo!

Learn more now.

Reach customers

searching for you.

Food Lovers

Real Food Group

on Yahoo! Groups

find out more.

.

__,_._,___
Brandon Long | 9 Aug 2008 00:32
Favicon

Re: sample file upload

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/

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Yahoo! Groups

Special K Challenge

Join others who

are losing pounds.

Yahoo! Groups

Join a program

to help you find

balance in your life.

.

__,_._,___
#!/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)
maxsimon1980 | 11 Aug 2008 11:56
Picon
Favicon

Re: sample file upload

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 ClearSilver <at> yahoogroups.com, Brandon Long <blong <at> ...> 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)
>

__._,_.___
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Ads on Yahoo!

Learn more now.

Reach customers

searching for you.

Yahoo! Groups

Find balance

between nutrition,

activity & well-being.

.

__,_._,___
Brandon Long | 11 Aug 2008 23:57
Favicon

Re: sample file upload

Yes, its possible. The code is obviously similar to the python from
before. The key point is, your HTML code must have a FORM element which
has the extra parameter for using multipart/form-data:

<form name=upload method=POST enctype="multipart/form-data">
<input type=file name=myfile>
</form>

Then, as normal, you need to call cgi_init and cgi_parse. That will
process the upload, placing the data in a file on disk in the /var/tmp
directory. You can change the directory the upload data goes into by
setting the HDF variable Config.Upload.TmpDir to something else.

Normally, the file is "unlinked" after being opened. This means the
file is only available to your process, and will be deleted as soon as
the process is ended. You can set Config.Upload.Unlink to 0 to stop
this behavior. If the files aren't automatically unlinked at creation
time, they will be cleaned up when cgi_destroy runs, but that won't
happen if your process dies prematurely, of course.

Normally, you can access the data in the file by using the
cgi_filehandle() function. This will return a FILE*, which you can use
to read the file on disk. Arguments are your CGI and also the form
element/query name, ie in the above example, that would be "myfile".

You can also get more information about the file, if its available. If
the browser provided a Content-Type with the upload, it'll be in the
Query.myfile.Type variable. The filename on the client as provided by
the browser will be in the Query.myfile variable. If you are not in
unlink mode, the filename on disk will be in Query.myfile.FileName. The
latter could be used to say link the file to another place on disk, for
instance.

You can get information during the upload (in cgi_parse) by setting up a
callback via cgi_register_parse_cb. There's a lot more information
about all of this in the comments in cgi/cgi.h

Brandon

On 08/11/08 maxsimon1980 uttered the following other thing:
> 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 ClearSilver <at> yahoogroups.com, Brandon Long <blong <at> ...> 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)
> >
>
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
--
"One of the main causes of the fall of the Roman Empire was that,
lacking zero, they had no way to indicate successful termination of
their C Programs." -- Robert Firth
http://www.fiction.net/blong/

__._,_.___
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Curves on Yahoo!

A group for women

to share & discuss

food & weight loss.

Everyday Wellness

on Yahoo! Groups

Find groups that will

help you stay fit.

.

__,_._,___
Jeevan | 12 Aug 2008 09:12
Picon
Favicon

please help me..

hello everyone.. hope all u r doing great.. i am new to this
clearsilver.. Now, I am in need of a file upload and a file download..
I cant find any more help from any other sites.. I have to use
clearsilver c api's for this upload process.. Can any one help me to
get a start with some sample codes....

Thanks in advance.
jeevan

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Real Food Group

on Yahoo! Groups

What does real food

mean to you?

Yahoo! Groups

Familyographer Zone

Learn how to capture

family moments.

.

__,_._,___
Brandon Long | 12 Aug 2008 22:53
Favicon

Re: please help me..

Hmm, second request for file upload help in as many days.

You can see my previous response here:

http://tech.groups.yahoo.com/group/ClearSilver/message/1201

File download is just like via any CGI, you probably want to do all of
the output yourself (ie, first print out the headers, probably
Content-Type and Content-Length, then an extra newline, then the file
contents). You can use stdio (ie, fwrite/printf) or use the wrappers
(especially if you're using FCGI, you'll need to use the wrappers),
which are defined in cgi/cgiwrap.h, cgiwrap_writef() and
cgiwrap_write().

Brandon

On 08/12/08 Jeevan uttered the following other thing:
> hello everyone.. hope all u r doing great.. i am new to this
> clearsilver.. Now, I am in need of a file upload and a file download..
> I cant find any more help from any other sites.. I have to use
> clearsilver c api's for this upload process.. Can any one help me to
> get a start with some sample codes....
>
> Thanks in advance.
> jeevan
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
--
"... one suspects that a really good Pentagon spokesperson could deny
the very existence of all earthly and cosmic matter, if asked by a
superior to do so, with a straight face ..." -- Today's Suck, 6/11/98
http://www.fiction.net/blong/

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Real Food Group

Share recipes,

restaurant ratings

and favorite meals.

.

__,_._,___
jeevan jothi | 13 Aug 2008 20:03
Picon
Favicon

Re: please help me..

Mr.Brandon, Thank you for your immediate response. The file download worked perfectly...!!!!!!!!! I have gone through your replies for file upload. In fact, I didnt get that Python code. I could not make it to write using C API's. Can you tell me something about  cgi_register_parse_cb(). Why should we have to register a callback? I am a bit confused with the parameters.. like void *rock. Where can I get more details about these API's. Even the comments in the source code is same as that in the clearsilver webpage.
http://www.clearsilver.net/docs/c_api.hdf

Thanks
Jeevan


Brandon Long <blong <at> fiction.net> wrote:

Hmm, second request for file upload help in as many days.

You can see my previous response here:

http://tech.groups.yahoo.com/group/ClearSilver/message/1201

File download is just like via any CGI, you probably want to do all of
the output yourself (ie, first print out the headers, probably
Content-Type and Content-Length, then an extra newline, then the file
contents). You can use stdio (ie, fwrite/printf) or use the wrappers
(especially if you're using FCGI, you'll need to use the wrappers) ,
which are defined in cgi/cgiwrap.h, cgiwrap_writef() and
cgiwrap_write().

Brandon

On 08/12/08 Jeevan uttered the following other thing:
> hello everyone.. hope all u r doing great.. i am new to this
> clearsilver.. Now, I am in need of a file upload and a file download..
> I cant find any more help from any other sites.. I have to use
> clearsilver c api's for this upload process.. Can any one help me to
> get a start with some sample codes....
>
> Thanks in advance.
> jeevan
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
--
"... one suspects that a really good Pentagon spokesperson could deny
the very existence of all earthly and cosmic matter, if asked by a
superior to do so, with a straight face ..." -- Today's Suck, 6/11/98
http://www.fiction.net/blong/


__._,_.___
Recent Activity
Visit Your Group
Give Back

Yahoo! for Good

Get inspired

by a good cause.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
maxsimon1980 | 20 Aug 2008 07:01
Picon
Favicon

File upload only with clearsilver C API

hello sir,

i have created a html file with following tags,

<form method="post" enctype="multipart/form-data" action="upload.cgi">
<tr class="ch_fl1">
<td class="input">
<input type="file" id="file1" name ="file">
<input name="filebtn" type="submit" value='submit'>
</td>
</tr>
</form>

and in my upload.cgi file i have written as,

int main (int argc, char **argv, char **envp)
{

NEOERR *err;
CGI *cgi;
char *cs_file;
char hdf_file[255];
char *p;
FILE *fp,*k;

cgi_debug_init (argc,argv);
cgiwrap_init_std (argc, argv, envp);

err = cgi_init(&cgi, NULL);
if (err != STATUS_OK)
{
cgi_neo_error(cgi, err);
nerr_log_error(err);
return -1;
}

err=hdf_set_value(cgi->hdf,"Config.Upload.TmpDir","var/tmp");

err = hdf_set_value(cgi->hdf, "Config.Upload.Unlink", "0");

err = parse_rfc2388 (cgi);
if (err != STATUS_OK)
{
cgi_neo_error(cgi, err);
nerr_log_error(err);
return -1;
}

err = hdf_write_file(cgi->hdf, "myhdffile.hdf");

err = cgi_display (cgi, "update.cs");
if (err != STATUS_OK)
{
cgi_neo_error(cgi, err);
nerr_log_error(err);
return -1;
}
return 0;
}

*********************************************************

when i write like this in my cgi file and i tried to upload it my the
localhost with Apache as my http server i got error in the apache log
file as,

[Tue Aug 12 16:28:20 2008] [error] [client 127.0.0.1] Traceback
(innermost last):\r, referer: http://localhost/cgi-bin/update.cgi
[Tue Aug 12 16:28:20 2008] [error] [client 127.0.0.1] File
"rfc2388.c", line 581, in parse_rfc2388()\r, referer:
http://localhost/cgi-bin/update.cgi
[Tue Aug 12 16:28:20 2008] [error] [client 127.0.0.1] File
"rfc2388.c", line 548, in _read_part()\r, referer:
http://localhost/cgi-bin/update.cgi
[Tue Aug 12 16:28:20 2008] [error] [client 127.0.0.1] File
"rfc2388.c", line 311, in open_upload()\r, referer:
http://localhost/cgi-bin/update.cgi
[Tue Aug 12 16:28:20 2008] [error] [client 127.0.0.1] SystemError:
Unable to open temp file var/tmp/cgi_upload.a03784: [2] No such file
or directory\r, referer: http://localhost/cgi-bin/update.cgi

I don't know whether i have made any error in writing my code .if
there is any error please guide me.

if you have any solution please kindly reply to me.
Thanks and regards in advance.

__._,_.___
New web site?

Drive traffic now.

Get your business

on Yahoo! search.

Learn to live

a full life with these

healthy living

groups on Yahoo!

Family Photos

Learn how to best

capture your

family moments.

.

__,_._,___
Gerald Dachs | 20 Aug 2008 09:10
Picon

Re: File upload only with clearsilver C API

> err=hdf_set_value(cgi->hdf,"Config.Upload.TmpDir","var/tmp");

try err=hdf_set_value(cgi->hdf,"Config.Upload.TmpDir","/var/tmp");

Gerald

----------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

__._,_.___
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

Yahoo! Groups

Familyographer Zone

Join a group and

share your pictures.

.

__,_._,___
breakthrough6 | 21 Aug 2008 22:02
Favicon

VC++

Has anyone successfully compiled CS under Visual Studio 2008 (VC++ 9.0)?

I know it's compiled for Windows using MingW (gcc++), but I'm
considering developing a Qt-based C++ wrapper around CS in VC++ and I
don't want to deal with lib conversions or issues between MingW and VC
to integrate with my other libraries smoothly.

Any insight would be greatly appreciated.

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Yahoo! Groups

Familyographer Zone

Learn how to take

great pictures.

Health Groups

for people over 40

Join people who are

staying in shape.

.

__,_._,___

Gmane