Hello friend,

So you want to upload images using cordova ?. Here I have written a simplified tutorial for uploading images with php backend also we have used camera plugin as image picker and cordova-plugin-filetransfer plugin for connecting remote server

Please login to download the latest source code

To avoid spam user, we only have social login • we do not post anything on your wall

Secured • No Spam


  • PHP based Web Server (you can use local web servers)
  • Cordova Camera Plugin (cordova-plugin-camera)
  • Cordova File Transfer Plugin (cordova-plugin-filetransfer)


  1. Writing Simple PHP code for receiving files from Mobile App
  2. Camera Plugin is used for accessing mobile Gallery
  3. Upload Images using File transfer plugin

Writing server side code

Let’s start with server side, I have a very simple php code which receives file & store it on uploads folder. so you must create uploads/ folder

    header('Access-Control-Allow-Origin: *');
    $new_image_name = urldecode($_FILES["file"]["name"]).".jpg";
    move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/".$new_image_name);

Important: Create a New Upload folder

Working with Cordova (PhoneGap)

Let’s start with mobile app side. so we can start with creating a new Cordova project and add required platforms and plugins. Here we need to also need add camera plugin (cordova-plugin-camera) for taking a picture from the camera (Refer: for more information about camera plugin)  & File transfer plugin (cordova-plugin-filetransfer) for uploading pictures to web server.

cordova create FileTransfer com.codesundar.filetransfer FileTransfer
cd FileTransfer

cordova platform add android

cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-file-transfer

2. Accessing Gallery using Camera Plugin, function(message) {
 alert('get picture failed');
 }, {
 quality: 100,

uploadPhoto is a success callback function & SourceType PHOTOLIBRARY used for accessing photo gallery

3. Uploading File to Remote Server

    <title>File Transfer Example</title>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript">
        var camearaOptions = {
            quality: 100,
        function getImage() {
  ,onError, camearaOptions);

        function onError(err){ alert(error); }

        function uploadPhoto(imageURI) {
            var options = new FileUploadOptions();
            options.fileKey = "file";
            options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
            options.mimeType = "image/jpeg";
            var ft = new FileTransfer();
            ft.upload(imageURI, "",
            function (result) {
            function (error) {
            }, options);

    <button onclick="getImage()">Upload a Photo</button>

Please login to download the latest source code

To avoid spam user, we only have social login • we do not post anything on your wall

Secured • No Spam

Cheers! Hope this helps.

If you faced any issue feel free to comment below.

Sundaravel M

About the author: Hi! I'm Sundaravel (codesundar), Founder of I have been a Web, Mobile App developer, Author, and Teacher since 2014. I also worked as a software consultant for fortune 500 companies. I created to share my real-time knowledge in various technologies such as PhoneGap, Ionic, Flutter and more.