Revlet save a txt file
Richard Gaskin
ambassador at fourthworld.com
Sun Jul 26 15:07:28 EDT 2009
Yves COPPE wrote:
> Le 26-juil.-09 à 19:51, Richard Gaskin a écrit :
>
>> Yves COPPE wrote:
>>
>>> 1) how can I save the txt file on my personal web site (it is not
>>> a rev-server)
...
> but for question 1)
> I don't master the POST comand
>
> I've hav read it in the dictionary
> but I cannot send the file on my webserver
>
> Can you please give me an example ?
This function can be used in a CGI to read incoming data and put it into
an array you can use later to obtain elements by name:
on _cgiGetInput
if "dev" is in the environment then
-- testing locally:
put gLocalTestInput into tBuffer
else
put empty into tBuffer
if $REQUEST_METHOD is "POST" then
-- POST:
repeat until (len(tBuffer) >= $CONTENT_LENGTH)
read from stdin until empty
put it after tBuffer
end repeat
--
else
-- GET:
put $QUERY_STRING into tBuffer
end if
--
end if
put tBuffer into gCGIDataInA
split gCGIDataInA by "&" and "="
end _cgiGetInput
I wrote it to use either the GET or POST method, and regardless which
one it uses it puts the data into the global array gCGIDataInA.
On the web data is often sent via POST using forms. So if you have a
form element containing your data whose value was "MyData", in the CGI
you can get that data like this:
global gCGIDataInA
on startup
_cgiGetInput
put gCGIDataInA["MyData"] into tData
--- do whatever else you need with that...
end startup
Since you're sending the data from a stack rather than from a web form,
all you need to do is package the data in the standard format, in which
the data is set up in name-value pairs, where the name and value are
separated by "=" and the pairs are separated with "&", e.g.:
MyData=SomeData&MyOtherData=MoreData
Rev makes sending this to the CGI a convenient one-liner:
post tData to url tCgiUrl
...where tData contains whatever data you want sent to the CGI, and
tCgiUrl is the url to your CGI, e.g.:
http://fourthworld.net/cgi-bin/revnet.cgi
For general info on getting started with Rev CGIs, check out Jacque's
excellent tutorial:
<http://www.hyperactivesw.com/cgitutorial/tutorialtoc.html>
It may take some experimentation to get things working well, but once
you do you'll have a really wonderful time with all the possibilities it
opens up.
RevNet contains examples of some of this stuff, such as the Feedback
form, which is just a stack that uses some handlers like
revnetSubmitForm stored in a backscript named RevNet_BS". You can find
RevNet in your Rev install in the menus at
Development->Plugins->GoRevNet. You're welcome to use any scripts there
you find handy.
--
Richard Gaskin
Fourth World
Revolution training and consulting: http://www.fourthworld.com
Webzine for Rev developers: http://www.revjournal.com
More information about the use-livecode
mailing list