Thanks again for your help! Yes, it’s certainly a strange issue. Unfortunately I’m still only getting “1” on the server for any params!
As I said, I’m quite new at this and learning as I go, so I can’t help wondering if simply out of inexperience I’ve accidentally created some other issue in my setup that’s causing this oddity.
Looking at all elements from the beginning, I have this state:
.state('menu.share', {
url: "/share",
cache: 'false',
views: {
'menuContent': {
templateUrl: "share.html",
controller: 'imageController'
}
}
})
And this controller:
.controller('imageController', function($scope, $cordovaCamera, $ionicPopup, $cordovaFile, $cordovaFileTransfer) {
//Get Photo From Camera
$scope.getPhoto = function() {
console.log('Hello camera');
$cordovaCamera.getPicture({
quality: 75,
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: 320,
targetHeight: 320,
saveToPhotoAlbum: false
}).then(function(FILE_URI) {
console.log(FILE_URI);
$scope.lastPhoto = FILE_URI;
}, function(err) {
console.err(err);
});
}
//Get Photo From Library
$scope.getLibrary = function() {
console.log('Hello library');
$cordovaCamera.getPicture({
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
quality: 75,
destinationType: Camera.DestinationType.FILE_URI,
targetWidth: 320,
targetHeight: 320,
saveToPhotoAlbum: false
}).then(function(FILE_URI) {
console.log(FILE_URI);
$scope.lastPhoto = FILE_URI;
}, function(err) {
console.err(err);
});
}
//Send To Server
$scope.uploadPhoto = function() {
var win = function (r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
$ionicPopup.alert({
title: 'Sweet.',
content: 'That worked.'
});
}
var fail = function (error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
$ionicPopup.alert({
title: 'Shit.',
content: 'Not quite.'
});
}
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = $scope.lastPhoto.substr($scope.lastPhoto.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.headers = {Connection: "close"};
options.chunkedMode = true;
var params = new Object();
params.name = "test";
options.params = params;
var ft = new FileTransfer();
ft.upload($scope.lastPhoto, encodeURI("http://www.server.com/uploader.php"), win, fail, options);
}
})
Sending to this PHP:
<?php
define('TIMEZONE', 'America/New_York');
date_default_timezone_set(TIMEZONE);
print_r($_FILES);
$name = $_POST["name"];
$new_image_name = print_r($name) . '@' . date('g:i:sa \o\n l, M jS, Y') . '.jpg';
move_uploaded_file($_FILES["file"]["tmp_name"], "wp-content/photos/test/".$new_image_name);
?>
And this view:
<ion-view view-title="Share">
<ion-content>
<p><button ng-click="getPhoto()" class="button button-block button-dark"><i class="icon ion-ios-camera"></i> <b> Take Photo</b></button></p>
<p><button ng-click="getLibrary()" class="button button-block button-dark"><i class="icon ion-ios-camera"></i> <b> Grab from Library</b></button></p>
<p><button ng-click="uploadPhoto()" class="button button-block button-dark"><i class="icon ion-share"></i> <b> Share Photo</b></button></p>
<center><img ng-src="{{lastPhoto}}" style="width: 100%; height: auto; overflow: scroll;"></div></center>
</ion-content>
</ion-view>
All of which works splendidly, besides the fact that my params only seem to send the number 1 to the server. Sigh…
Do you perhaps see anything I’ve obviously gotten wrong here that would cause such an issue?