0 Replies Latest reply on Mar 1, 2018 3:54 AM by juliomgm

    Make simple file upload


      I am trying to upload a file using phonegap, but i am stuck.


      In phonegap I made this test file - upload.html

      <!DOCTYPE html>



          <title>File Upload</title>



          <script type="text/javascript" src="cordova.js"></script>

          <script type="text/javascript" charset="utf-8">

              document.addEventListener('deviceready', onDeviceReady, false); 

              function onDeviceReady() {


                  function win(r) {

                      document.getElementById("demo3").innerHTML = "File Upload OK." ;

                      console.log('Upload OK.');



                  function fail(error) {

                      document.getElementById("demo3").innerHTML = "An error has occurred." ;

                      console.log('Upload ERROR.');



                  var uri = encodeURI("http://www.--------.com/webspace/upload.php");

                  var pathToFile = cordova.file.dataDirectory + 'example.txt' ;


                  var options = new FileUploadOptions();





                  document.getElementById("demo1").innerHTML = pathToFile ;

                  document.getElementById("demo2").innerHTML = pathToFile.substr(pathToFile.lastIndexOf('/')+1);


                  console.log('Upload Begin.');

                  var ft = new FileTransfer();

                  ft.upload(pathToFile, uri, win, fail, optionsoptions);





          <p id="demo1"></p>

          <p id="demo2"></p>

          <p id="demo3"></p>




      In my server I have upload.php



          $uploaddir = 'upload/';

          $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);


          if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

              echo "File successfully uploaded.\n";





      I already removed cordova-plugin-file-transfer and added it again.


      I dont know what else to do