$headers = getallheaders();
if ($headers["Content-Type"] == "application/json") {
$jsondata = file_get_contents("php://input");
$data = json_decode($jsondata,TRUE);
echo ($data['SBP_Category']."/".$data['SBP_Details']);
echo ($data['upload_file']);
}
if (isset($_FILES['upload_file'])) {
if(move_uploaded_file($_FILES['upload_file']['tmp_name'], "temp/" . $_FILES['upload_file']['name'])){
echo $_FILES['upload_file']['name']. " OK";
} else {
echo $_FILES['upload_file']['name']. " KO";
}
exit;
} else {
echo "No files uploaded ...";
}
Request URL:http://strxxx.co.uk/SBPostPost.php
Request Method:POST
Status Code:200 OK
Request Headers
Provisional headers are shown
Content-type:application/json
Origin:http://127.0.0.1:58889
Referer:http://127.0.0.1:58889/http-services/emulator-webserver/ripple/userapp/x/C/Users/Phils/AppData/Local/XDK/xdk-scratchdir/e14eb410-7cf2-4bed-ba25-515e6df98e8c/platforms/ios/www/index.html
User-Agent:Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4
X-DevTools-Emulate-Network-Conditions-Client-Id:BFC389F1-2AF4-4347-8AC1-F9144DC2DA25
Request Payloadview source
{SBP_Category:Select, SBP_Details:xxxxx Detail xxxx, upload_file:[object File]}
SBP_Category: "Select"
SBP_Details: "xxxxx Detail xxxx"
upload_file: "[object File]"
Response Headers
Content-Encoding:gzip
Content-Length:251
Content-Type:text/html
Date:Sun, 20 Sep 2015 13:11:33 GMT
Server:Microsoft-IIS/8.5
Vary:Accept-Encoding
<script>
function sendDataJS()
{
var xmlhttp = new XHRObject();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('ResponseDiv').innerHTML = "Entry Posted";
}
}
var postdata = '{';
postdata += '"SBP_Category": "' + document.getElementById('Category').value + '"';
postdata += ',"SBP_Details": "' + document.getElementById('Details').value + '"';
postdata += ',"upload_file": "' + document.getElementById('mypic').files[0] + '"';
postdata += '}';
xmlhttp.open("POST","http://strxxx.co.uk/SBPostPost.php", false);
xmlhttp.setRequestHeader("Content-type","application/json");
xmlhttp.send(postdata);
}
Getting very confused by all the options available - could someone please help.
I'm developing a hybrid HTML5/JS App in XDK that sends data to a PHP server. I can get at the data fields but struggling with a file (image).
The JS that sends is as above; preceded by the console Log - which looks like it is sending the file ok as an object
The PHP is also attached -
What happens is that the Data in Category and Detail is echoed back fine; the echo of $Data['ipload_file'[ shows 'object' - BUT the If ISSET echoes 'No Files uploaded'
Any help appreciated.
By the way - the extracts above may be in wrong order - had trouble getting them into the post