Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9016957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:08:21+00:00 2026-06-16T04:08:21+00:00

I’m using Phone Gaps (Cordova 2.1) file transfer API to post an image from

  • 0

I’m using Phone Gaps (Cordova 2.1) file transfer API to post an image from the users photo library to my server. The file transfer API seems to be working fine. I’m just puzzled about retrieving this information on my server.

Ideally, what I need to do is retrieve the image then upload it to my server. However, I can’t seem to retrieve any information from the file transfer?

My JavaScript code (posting image data) is:

function onDeviceReady() {

            // Retrieve image file location from specified source
            navigator.camera.getPicture(uploadPhoto,
                                        function(message) { alert('get picture failed'); },
                                        { quality: 50, 
                                        destinationType: navigator.camera.DestinationType.FILE_URI,
                                        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY }
                                        );

        }

        function uploadPhoto(imageURI) {
            var options = new FileUploadOptions();
            options.fileKey="file";
            options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
            options.mimeType="image/jpeg";

            var params = {};
            params.value1 = "test";
            params.value2 = "param";

            options.params = params;

            var ft = new FileTransfer();
            ft.upload(imageURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);
        }

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

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

My server side code is:

 $paramValue = $_POST['fileKey']; //Undefined variable
 $paramValue2 = $_POST['options']; //Undefined variable
$paramValue3 = $paramValue2['fileKey'] //Undefined variable

I’ve also tried:

//POST variable
$paramValue = $_POST['params'];
echo "Param Value1: " . $paramValue['value1']; //Should return "test"

I’ve also tried:

//POST variable
$paramValue = $_POST['options'];
echo "Param Value1: " . $paramValue['options']['params']['value1']; //Should return "test"

All I’m getting is undefined variable errors?

Any help would be much appreciated, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:08:22+00:00Added an answer on June 16, 2026 at 4:08 am

    On http://some.server.com you can have your /var/www/ directory, in this directory you need upload.php and the code in this directory should move your image to the folder

    /var/www/TEST/

    <?php
       print_r($_FILES);
       $new_image_name = "YEAH.jpg";
       move_uploaded_file($_FILES["file"]["tmp_name"], "/var/www/TEST/".$new_image_name);
    ?>
    

    That is the only extra thing you need.

    Prerequisite:

    XAMPP LAMP WAMP or MAMP on your http://some.server.com

    For clarity, this is the JavaScript and HTML just to show you how my upload.php file fits in:
    In your head

    <script type="text/javascript" charset="utf-8">
    
    // Wait for PhoneGap to load
    document.addEventListener("deviceready", onDeviceReady, false);
    
    // PhoneGap is ready
    function onDeviceReady() {
        console.log("device ready");
        // Do cool things here...
    }
    
    function getImage() {
        // Retrieve image file location from specified source
        navigator.camera.getPicture(uploadPhoto, function(message) {
                    alert('get picture failed');
                },{
                    quality: 50,
                    destinationType: navigator.camera.DestinationType.FILE_URI,
                    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
                }
        );
    
    }
    
    function uploadPhoto(imageURI) {
        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";
    
        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";
    
        options.params = params;
        options.chunkedMode = false;
    
        var ft = new FileTransfer();
        ft.upload(imageURI, "http://some.server.com/TEST/upload.php", win, fail, options);
    }
    
    function win(r) {
        console.log("Code = " + r.responseCode.toString()+"\n");
        console.log("Response = " + r.response.toString()+"\n");
        console.log("Sent = " + r.bytesSent.toString()+"\n");
        alert("Code Slayer!!!");
    }
    
    function fail(error) {
        alert("An error has occurred: Code = " + error.code);
    }
    
    </script>
    
    </head>
    

    and this is what I have in my body

    <button onclick="getImage();">Upload a Photo</button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am using jsonparser to parse data and images obtained from json response. When
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.