odk with php mysql

Solutions on MaxInterview for odk with php mysql by the best coders in the world

showing results for - "odk with php mysql"
Emilee
25 Sep 2016
1<?php
2//With default Collect Submission path setting, this script would be located at https://your.server/submission/index.php
3//this is where all the uploaded files will eventually be stored.
4$datapath='/path/to/your/datafiles/';
5//Set a variable to tell us whether an XML file has successfully been uploaded later:
6$xmlfile=false;
7//we need to process POST and HEAD requests separately, and cater for GET just in case
8$method=strtolower($_SERVER['REQUEST_METHOD']);
9//Issue these response headers to both HEAD and POST requests:
10header("Content-Type: text/xml; charset=utf-8");
11header("Content-Language: en");
12header("X-OpenRosa-Version: 1.0");
13header("X-OpenRosa-Accept-Content-Length: 10000000");//limit upload to 10Mb - probably too high for most realistic scenarios!
14//Now process POST and HEAD requests differently
15if ($method=='post') {
16	//we should have at least one POSTED file
17	if (isset($_FILES)) {
18		//we need to move all the POSTed files from the tmp upload folder, as with any file POST, then respond with a Success code and message.
19		foreach($_FILES as $file) {
20			$filename=$file['name'];
21			$ok=move_uploaded_file($file['tmp_name'],$datapath.$filename);
22			//There should only be one XML file, which is the completed form.  Any other files are assets, whose file names will be included in the form data.
23			if ($file['type']=="text/xml") $xmlfile=$file['name'];
24		}
25		header("HTTP/1.1 202 Accepted");
26		echo '<?xml version="1.0" encoding="UTF-8" ?>';
27		echo '<OpenRosaResponse xmlns="http://openrosa.org/http/response" items="1">';
28		echo '<message nature="submit_success">Form submitted successfully</message>';
29		echo '</OpenRosaResponse>';	
30	}
31	else {
32		/* If $_FILES is not set in the POST, that means we have no XML file of the completed form, so we need to return an error.  This should really be a 400, but 
33		in my original implementation circa 2012, Collect didn't interpret a 400 response correctly, and only a 403 response would produce a human-readable 
34		error message in Collect. */
35		header("HTTP/1.1 403 Forbidden");
36		echo '<?xml version="1.0" encoding="UTF-8" ?>';
37		echo '<OpenRosaResponse xmlns="http://openrosa.org/http/response" items="1">';
38		echo  '<message nature="submit_success">Submission unsuccessful - no data files were received.</message>';
39		echo '</OpenRosaResponse>';	
40	}
41}
42if ($method=='head' || $method=='get') { 
43	//This is the initial HEAD request from Collect, so we need to return a Location header telling Collect where to POST the completed form.  
44	//We also provide this response to GET requests to give us browser testing options.
45	header("Location: $_SERVER[SCRIPT_URI]");//this script - 
46	header("HTTP/1.1 204 No Content");//that's all, no actual content in the response.
47}
48if ($xmlfile!==false){
49  //now process the contents of $path.$xmlfile however you want to!
50  require 'my_form_processor_script.php';	
51}
52?>
53
queries leading to this page
odk with php mysqlodk with php mysql