Jonny S Jonny S - 1 year ago 189
PHP Question

"Disallowed key characters in global data" with Unicode garbage

Searched through the Overflow to see if I can spot a solution to this issue, but unfortunately nothing seems to be specific enough.

I'm building an Ionic app with a photo upload feature (using the cordova-filetransfer plugin), and have an API endpoint set up to receive the image. The Ionic JS is able to process the image successfully, but the API responds back with the "disallowed keys" error; only it's full of random garbled nonsense.



public function clean_input_keys($str)
$chars = PCRE_UNICODE_PROPERTIES ? '\pL' : 'a-zA-Z';

if ( ! preg_match('#^['.$chars.'0-9:_.-]++$#uD', $str))
exit('Disallowed key characters in global data: '.$str."\n [GLOBAL vars] \n".Kohana::debug($GLOBALS));

return $str;

The full response:

Disallowed key characters in global data: '()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÛ
[GLOBAL vars]
<pre>array: </pre>

function from the mobile app:

$scope.uploadImage = function(datetime) {

// Destination URL
var uploadUrl = "url/goes/here";

// File for Upload
var imagePath = $scope.urlForImage($scope.image);
console.log('Path: '+imagePath);

// File name only
var filename = $scope.addZero(datetime.getDate()) + $scope.addZero((datetime.getMonth() + 1)) + datetime.getFullYear() + '-' + $scope.addZero(datetime.getHours()) + $scope.addZero(datetime.getMinutes()) + '-' + $ + '-' + $scope.incidentData.location + '.jpg';
filename = filename.replace(/\s+/g, '');
console.log('Filename: '+filename);

var success = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);

var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("Upload error source " + error.source);
console.log("Upload error target " +;

var options = new FileUploadOptions();
options.fileKey = "image";
options.fileName = filename;
options.chunkedMode = false
//mimeType: "multipart/form-data",
options.mimeType = "image/jpeg";

var params = {};
params.fileName = filename;

options.params = params;

var headers = {
"API-Key": "keygoeshere",
"Content-Type": "application/x-www-form-urlencoded"

options.headers = headers;

var ft = new FileTransfer();

ft.upload(imagePath, uploadUrl, success, fail, options);

And the API endpoint function:

public function upload_image()

$file_temp = $_FILES['image']['tmp_name'];
$file_name = $_FILES['image']['name'];
$target_path = 'path/goes/here';

if (move_uploaded_file($file_temp, $target_path.$file_name)) {
Kohana::log('debug', 'File received: '.$_FILES['image']['name']);
} else {
Kohana::log('debug', 'Photo upload failed');

Sorry if this is a bit too much code, but I cannot work out for the life of me where this error is stemming from - any advice?

Answer Source

The issue turned out to be the headers: I was posting a header (Content-Type) that the plugin already sends by default; the two were clashing and causing the error.

Removing this header, leaving only the API-Key, has allowed the image to be sent.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download