Stress Upload Image Cannot work,Help me

I get this tutorial in this forum and try all tutorial for upload images but cannot work along 2 weeks

app.js

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// ‘starter’ is the name of this angular module example (also set in a attribute in index.html)
// the 2nd parameter is an array of ‘requires’
var starter = angular.module(‘starter’, [‘ionic’,‘ngCordova’])

.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

  // Don't remove this line unless you know what you are doing. It stops the viewport
  // from snapping when text inputs are focused. Ionic handles this internally for
  // a much nicer keyboard experience.
  cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
  StatusBar.styleDefault();
}

});
});

starter.controller(‘ImageController’, function($scope,$cordovaFileTransfer,$ionicPopup,$ionicLoading,$http) {

  $http.post('http://uh.com/image/www/server/download.php')
	.then(successCallback, errorCallback);
  
  function successCallback(data) {
	  $scope.dbimages = data.data;
	  console.log($scope.dbimages);
  }
  
  function errorCallback() {
	  console.log('error');
  }
  $scope.getGallery = function () {
        window.imagePicker.getPictures(
            function (results) {
                for (var i = 0; i < results.length; i++) {
                    // Destination URL 
                    var url = 'http://uh.com/image/www/server/upload.php';
                    var targetPath = results[i];
                    // File name only
                    var filename = targetPath.split("/").pop();
                    var options_tosend = {
                        fileKey: "file",
                        fileName: filename,
                        chunkedMode: false,
                        mimeType: "image/jpg",
                        params: {'directory': 'upload', 'fileName': filename }
                    };
                    $cordovaFileTransfer.upload(url, targetPath, options_tosend).then(function (result) {
                        console.log("SUCCESS: " + JSON.stringify(result.response));
                        $ionicPopup.alert({
                            title: 'Success!',
                            template: 'Image Uploaded Successfully'
                        });
                        $ionicLoading.hide();
                    }, function (err) {
                        console.log("ERROR: " + JSON.stringify(err));
                        $ionicPopup.alert({
                            title: 'Sorry!',
                            template: 'Profile Image not changed , Please try again'
                        });
                        $ionicLoading.hide();
                        
                    }, function (progress) {
                        // PROGRESS HANDLING GOES HERE
                        $ionicLoading.show({
                            template: 'Updating Image...'
                        });  
                    });
                }
            }, function (error) {
        console.log('Error: ' + error);
    },{
        maximumImagesCount: 1,
        width: 500,
        height: 500,
        quality: 10
    }
    );
};

});

index.html

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<ion-pane>      
  <ion-header-bar class="bar-stable">
      <h1 class="title">Image Example</h1>
  </ion-header-bar>
  <ion-content ng-controller="ImageController">
       <button class="button button-full button-positive" ng-click="getGallery()">
           Pick Image
       </button>
       <h2>All DB Images</h2>
       <span ng-repeat="i in dbimages">
		   <img src="{{i.image}}"> 
	</span>
  </ion-content>
</ion-pane>

Server in hosting upload.php

<?php header('Access-Control-Allow-Origin: *'); include 'config.php'; $location = $_POST['directory']; $uploadfile = $_POST['fileName']; $uploadfilename = $_FILES['file']['tmp_name']; $type = pathinfo($uploadfile, PATHINFO_EXTENSION); if (move_uploaded_file($uploadfilename, $location . '/' . $uploadfile)) { $imagedata = file_get_contents($location . '/' . $uploadfile); $base64 = base64_encode($imagedata); unlink($location . '/' . $uploadfile); $image = 'data:image/' . $type . ';base64,' . $base64; $link = mysql_connect($config['host'], $config['username'], $config['password']); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db($config['database'], $link); $q = "INSERT into `ionic`.`ionic` (`image`) VALUES ('$image')"; $result = mysql_query($q); echo $result; } else { echo 'Upload error!' . 'location: ' . $location; } ?>

config.php

<?php $config = array( 'host' => 'localhost', 'username' => 'root', 'password' => 'welcome', 'database' => 'ionic' ); ?>

SQL
image

When i choose picture in gallery on phone success but when i upload cannot insert database.Ionic Popup Successfull but not inser in folder upload in hosting and sql