File-Transfer Cordova how to use php

2

Hello, I have the following code

 onDeviceReady: function () {
    navigator.camera.getPicture(
                app.uploadPhoto,
                function (message) { alert('get picture failed'); },
                {
                    quality: 50,
                    destinationType: navigator.camera.DestinationType.FILE_URI,
                    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
                }
            );
},
uploadPhoto: function(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://192.168.0.101/upload/index.php"), app.win, app.fail, options);
},

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

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

It's working, but when I upload to my php I do not know how to save, my php looks like this:

    <?php
move_uploaded_file($_FILES["file"]["tmp_name"], 'C:\xampp\htdocs\upload\images');
    ?>

I would like to save within C:\xampp\htdocs\upload\images , how should my php be?

    
asked by anonymous 28.04.2015 / 15:48

1 answer

1

I was able to make it work as follows, js stayed like this.

ft.upload(fileURI, encodeURI("http://192.168.0.102/upload/index.php"), app.win, app.fail, options);

The index.php receives and sends it to the 'images' folder within 'upload'.

 <?php
    $new_image_name = strtolower($_FILES['file']['name']);
    move_uploaded_file($_FILES["file"]["tmp_name"], "images/".$new_image_name);
    
29.04.2015 / 15:29