Aller au contenu principal

cgidata

parse cgidata

CGIDATA

NAME

cgidata - parse cgidata

SYNOPSIS

cgidata(parse_get : true|false, parse_post : true|false, conflict : replace|array|keep|join, join : "join string", callback : "…", postmax : integer, disable_upload : true|false, directory : "directory upload", fileconflict : "overwrite | rename | error", maxsize : 456, extention : "jpg,png,gif", ct : "format/gif, image/jpeg", "file parameter" : { directory : "directory upload to overwrite default directory upload", url : "url….", fileconflict : "overwrite|rename|error", maxsize : 456, ct : …, extention : …}, esc_cgidata:bool,error:variable)

DESCRIPTION

This function is used to read parameters passed threw cgidata. The parameters can be GET or POST. By default all parameters are read and return as an associative array.

This function can only be called once per request. If the function ia called twice, then the previous result is return even if the arguments are not the same.

cgidata can be used to read data with content-type of

  • application/x-www-form-urlencoded
  • multipart/form-data
  • application/json. In this case, a string will be return and if it is valid JSON, you can use unstringify to get the actual JSON.

When an input type file has the parameters multiple, then name parameter will be an array of image transmit by the form. This feature is available with version 5.73.

An example of application/x-www-form-urlencoded is the following:

json.sn:


        a = cgidata();
        if a.s != undefined then
                b=unstringnify(a.s);
                ret = { error : 0 };
                ret.msg = "No error with " .+ b.userName;
                ret;
        else
                include("json2.sn");
        endif

json2.sn:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
    <script language="javascript" src="jquery.js"></script>
</head>
<body>
        <h1>Json test</h1>
        <p>This test is used to test exchange between sncode and js with json</p>
        <p>A form is used to send a json request and the answer if sent back in json</p>
        <a href="#" onClick="send();">Execute</a>
        <script language="javascript">
                function send() {
                        var userName = "laplante";
                        var password = "pierre";
                        var a = JSON.stringify({ "s":"t","userName": userName, "password" : password });
                         $.ajax ({
                                 type: "POST",
                                 url: '?s='+a,
                                 dataType: 'json',
                                 async: false,
                                 success: function (data) {
                                         alert("Thanks!" + data.error + " " + data.msg);
                                 }
                         })
                }
                $(document).ready(function() {
                });
        </script>
</body>
</html>

 

PARAMETERS

 

Here is the list of parameters:

parse_get
Determine if we parse get. By default, this value is true. GET parameters in HTTP is what is passed on the URL.
ct
Limit upload to those Content-type. Multiple Content-type can be specify separated by a comma. 
callback
This option define a function that can be used as a callback while reading data from post data for upload file. The function is called while reading with the following parameters:
  • maxsize:64000 maxsize allowd
  • finish:false upload for this file is finish or not
  • nbupload:1 nbupload so far
  • size:0 size so far
  • totalsize:31903 total size of all upload
conflict
Determine how to resolve conflict in variable name. Possible value are:
  • replace
  • array
  • keep
  • join
join
Specify joing string. Default is comma : ,.
postmax
Integer value for maximum number of allowed byte in post. Default specify in configuration file.
disable_upload
Make sure upload are not allowed. true by default.
directory
Specify directory where to upload file. /tmp by default.
 
error
use to catch error in variable.
file parameter
Specify where to upload this file and all other info regarding the file such as what to do when there's conflict, maximum size is allowed for the file. Parameter URL is to to build the return value sn_url and sn_fullurl which are return.
file_field_name:{
                "directory":"/upload", // directory for uploading the files, No default value. If no value is specify, parameter directory is used.
                "fileconflict":"overwrite" // ovewrites old file if exists. Other options: rename, error
            });
Please note that the "file_field_name" is important. It should be the form field name for the file field.
 
esc_cgidata
If this parameter is true, that all data read by cgidata will be escape. < will be replace by &lt;, > will be replace by &gt; and & will be replace by &amp; Also, the original value
of a paramerer (without escaping) will be put in the name of the parameter prefix by sn_. So if the parameter is call test than cgidata.test will contain the escape value sn sn_test
will contain the original value. This parameter if valid from version 5.48 of sncode. See also configuration parameter esc_cgidata. By default the value of this parameter is false
unless esc_cgidata is true in the configuration file.

RETURN

An associative array of each parameters. For a filename the following will be return: - filename : initial filename. - sn_size : size of filename in bytes. - sn_filename : new name in case of conflict. - sn_dir : directory where the file has been uploaded. - sn_path : directory where the file is save - sn_fullname : sn_path/sn_filename - sn_url : url for the file - sn_fullurl : sn_url / sn_filename - … : others parameters passed with the file. Exemple: ct for content type.

EXAMPLES

res={}. return res={"a":"éé","c":"d"}. with arguments '?a=éé&c=d'
res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d'
res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d'
res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f"
res={}. return res={"a":"éé","c":"d","e":"f"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f"
res={}. return res={"a":"éé","c":"d","e":"f"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?e=f"
res={}. return res={"a":"f,éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={}. return res={"a":"éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={}. return res={"a":"f","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={}. return res={"a":"f,éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={}. return res={"a":"f;éé","c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
res={}. return res={"a":\["f","éé"\],"c":"d"}. with arguments 'a=éé&c=d', "http://v5.sednove.ca/test.sn?a=f"
a = cgidata(image : { directory : "/tmp", fileconflict : "error" });

SEE ALSO

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

1.2 2014-10-12 laplante@sednove.com Return last result if called twice

1.3 2016-03-08 laplante@sednove.com Add esc_cgidata

Edit

© 2024 extenso Inc. All rights reserved.