title: Phonegap capture photo and upload to server
body: <p>I am facing a problem here for my code. Whenever I put in my function uploadPhoto, the function capturePhotoWithFile would not work(I pressed the button but nothing happened). However when I remove the function uploadPhoto, the function capturePhotoWithFile would work again(I could pressed the button and take a photo).</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Capture Photo&lt;/title&gt;
  &lt;meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"/&gt;
  &lt;script type="text/javascript" charset="utf-8" src="phonegap.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" charset="utf-8"&gt;
  
  var pictureSource;   // picture source
  var destinationType; // sets the format of returned value 
  
  document.addEventListener("deviceready",onDeviceReady,false);
  
  function onDeviceReady() {
      pictureSource=navigator.camera.PictureSourceType;
      destinationType=navigator.camera.DestinationType;
  }
  
  function onPhotoFileSuccess(imageData) {
    console.log(JSON.stringify(imageData));
    var smallImage = document.getElementById('smallImage');
    smallImage.style.display = 'block';
    smallImage.src = imageData;
  }
  
   function capturePhotoWithFile() {
      navigator.camera.getPicture(onPhotoFileSuccess, onFail, { quality: 50, destinationType:      Camera.DestinationType.FILE_URI });
  }
  
  function onFail(message) {
    alert('Failed because: ' + message);
  }
  
  
  function uploadPhoto() {
  
      var imageData = document.getElementById('smallImage').getAttribute("src");
      if (!imageData) {
          alert('Please select an image first.');
          return;
      }
  
      var options = new FileUploadOptions();
      options.fileKey = "file";
      options.fileName = imageData.substr(imageData.lastIndexOf('/')+1);
      options.mimeType = "image/jpeg";
  
      }
  
      var ft = new FileTransfer();
      ft.upload(imageData, encodeURI("uploadtest.php"), win, fail, options);
      }
  
      function onFail(message) {
      console.log('Failed because: ' + message);
      }
  
      function win(r) {
      console.log("Code = " + r.responseCode);
      console.log("Response = " + r.response);
      //alert("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);
      }
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;button onclick="capturePhotoWithFile();"&gt;Capture Photo&lt;/button&gt; &lt;br&gt;
  &lt;button onclick="uploadPhoto();"&gt;Upload&lt;/button&gt; &lt;br&gt;
  &lt;img style="display:none;width:60px;height:60px;" id="smallImage" src="" /&gt;
  &lt;img style="display:none;" id="largeImage" src="" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>