Uploading video from phonegap to php












3















I am using this phonegap(js) code to upload a recorded video to php server.



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<title>Mobile_Insurance</title>

</head>
<body>

<script type="text/javascript">

$(document).ready(function(){
$('input[name="visit"]').click(function(){
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".box").not(targetBox).hide();
$(targetBox).show();
});
});


function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}

// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 2 video clips
navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 1});
}

// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
var options = new FileUploadOptions();
options.chunkedMode = true;
options.fileKey = "file";
options.fileName = name;
options.mimeType = "video/mp4";
var params = new Object();
params.value1 = "test";
params.value2 = "param";

options.params = params;

ft.upload(path, "http://192.168.0.46/upload/upload.php",
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
console.log("Response = " + r.response);
alert("Response = " + r.response);
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
alert('Error uploading file ' + path + ': ' + error.code);
},
options);
alert(mediaFile.fullPath);
}
</script>
<script type="text/javascript" src="cordova.js"></script>
<div data-role="page">
<div data-role="header">
<h3>Welcome </h3>
</div>
<div data-role="main" class="ui-content">
<h3 style="text-align: center;">Input Your IMEI:</h3>
<input type="number"/>
<h3 style="text-align: center;"> yes?</h3>

<input type="radio" name="visit" value="YES" id="Video">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="visit" value="NO" id="self">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO
<br>
<h3 style="text-align: center;"> damage.</h3>
<input type="radio" name="damage" value="Physical">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Physical
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="damage" value="Water">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Water <br><br>
<h3 style="text-align: center;">Please give a breig description about the damage</h3><br>
<textarea rows="5" cols="10" style="resize:none"></textarea>
<div class="YES box"><input type="button" value="self analysis" hidden="true"></div>
<div class="NO box"> <button onclick="captureVideo();">Capture Video</button></div>

</div>
</div>
</body>
</html>


This is my php code..



<?php
print_r($_FILES);
$new_image_name = "r.mp4";
move_uploaded_file($_FILES["file"]["tmp_name"], $new_image_name);
?>


The uploadFile function is supposed to upload the file to the specified php file. but in my case the phonegap filetransfer is giving error code 1 which is file not found. I have alert the file path after capture which is same file to be uploaded. How is it throwing error code 1?










share|improve this question























  • and how mediaFile.fullPath looks like?

    – jcesarmobile
    Jun 1 '17 at 9:41











  • file:///storage/emulated/0/DCIM/Camera/20170601_144112.mp4

    – Tridev Chaudhary
    Jun 1 '17 at 9:43











  • Read the plugin compatibility notes, fullPath is not supported github.com/apache/…

    – jcesarmobile
    Jun 1 '17 at 9:50
















3















I am using this phonegap(js) code to upload a recorded video to php server.



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<title>Mobile_Insurance</title>

</head>
<body>

<script type="text/javascript">

$(document).ready(function(){
$('input[name="visit"]').click(function(){
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".box").not(targetBox).hide();
$(targetBox).show();
});
});


function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}

// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 2 video clips
navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 1});
}

// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
var options = new FileUploadOptions();
options.chunkedMode = true;
options.fileKey = "file";
options.fileName = name;
options.mimeType = "video/mp4";
var params = new Object();
params.value1 = "test";
params.value2 = "param";

options.params = params;

ft.upload(path, "http://192.168.0.46/upload/upload.php",
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
console.log("Response = " + r.response);
alert("Response = " + r.response);
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
alert('Error uploading file ' + path + ': ' + error.code);
},
options);
alert(mediaFile.fullPath);
}
</script>
<script type="text/javascript" src="cordova.js"></script>
<div data-role="page">
<div data-role="header">
<h3>Welcome </h3>
</div>
<div data-role="main" class="ui-content">
<h3 style="text-align: center;">Input Your IMEI:</h3>
<input type="number"/>
<h3 style="text-align: center;"> yes?</h3>

<input type="radio" name="visit" value="YES" id="Video">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="visit" value="NO" id="self">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO
<br>
<h3 style="text-align: center;"> damage.</h3>
<input type="radio" name="damage" value="Physical">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Physical
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="damage" value="Water">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Water <br><br>
<h3 style="text-align: center;">Please give a breig description about the damage</h3><br>
<textarea rows="5" cols="10" style="resize:none"></textarea>
<div class="YES box"><input type="button" value="self analysis" hidden="true"></div>
<div class="NO box"> <button onclick="captureVideo();">Capture Video</button></div>

</div>
</div>
</body>
</html>


This is my php code..



<?php
print_r($_FILES);
$new_image_name = "r.mp4";
move_uploaded_file($_FILES["file"]["tmp_name"], $new_image_name);
?>


The uploadFile function is supposed to upload the file to the specified php file. but in my case the phonegap filetransfer is giving error code 1 which is file not found. I have alert the file path after capture which is same file to be uploaded. How is it throwing error code 1?










share|improve this question























  • and how mediaFile.fullPath looks like?

    – jcesarmobile
    Jun 1 '17 at 9:41











  • file:///storage/emulated/0/DCIM/Camera/20170601_144112.mp4

    – Tridev Chaudhary
    Jun 1 '17 at 9:43











  • Read the plugin compatibility notes, fullPath is not supported github.com/apache/…

    – jcesarmobile
    Jun 1 '17 at 9:50














3












3








3








I am using this phonegap(js) code to upload a recorded video to php server.



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<title>Mobile_Insurance</title>

</head>
<body>

<script type="text/javascript">

$(document).ready(function(){
$('input[name="visit"]').click(function(){
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".box").not(targetBox).hide();
$(targetBox).show();
});
});


function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}

// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 2 video clips
navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 1});
}

// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
var options = new FileUploadOptions();
options.chunkedMode = true;
options.fileKey = "file";
options.fileName = name;
options.mimeType = "video/mp4";
var params = new Object();
params.value1 = "test";
params.value2 = "param";

options.params = params;

ft.upload(path, "http://192.168.0.46/upload/upload.php",
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
console.log("Response = " + r.response);
alert("Response = " + r.response);
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
alert('Error uploading file ' + path + ': ' + error.code);
},
options);
alert(mediaFile.fullPath);
}
</script>
<script type="text/javascript" src="cordova.js"></script>
<div data-role="page">
<div data-role="header">
<h3>Welcome </h3>
</div>
<div data-role="main" class="ui-content">
<h3 style="text-align: center;">Input Your IMEI:</h3>
<input type="number"/>
<h3 style="text-align: center;"> yes?</h3>

<input type="radio" name="visit" value="YES" id="Video">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="visit" value="NO" id="self">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO
<br>
<h3 style="text-align: center;"> damage.</h3>
<input type="radio" name="damage" value="Physical">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Physical
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="damage" value="Water">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Water <br><br>
<h3 style="text-align: center;">Please give a breig description about the damage</h3><br>
<textarea rows="5" cols="10" style="resize:none"></textarea>
<div class="YES box"><input type="button" value="self analysis" hidden="true"></div>
<div class="NO box"> <button onclick="captureVideo();">Capture Video</button></div>

</div>
</div>
</body>
</html>


This is my php code..



<?php
print_r($_FILES);
$new_image_name = "r.mp4";
move_uploaded_file($_FILES["file"]["tmp_name"], $new_image_name);
?>


The uploadFile function is supposed to upload the file to the specified php file. but in my case the phonegap filetransfer is giving error code 1 which is file not found. I have alert the file path after capture which is same file to be uploaded. How is it throwing error code 1?










share|improve this question














I am using this phonegap(js) code to upload a recorded video to php server.



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<title>Mobile_Insurance</title>

</head>
<body>

<script type="text/javascript">

$(document).ready(function(){
$('input[name="visit"]').click(function(){
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".box").not(targetBox).hide();
$(targetBox).show();
});
});


function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}

// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 2 video clips
navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 1});
}

// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
var options = new FileUploadOptions();
options.chunkedMode = true;
options.fileKey = "file";
options.fileName = name;
options.mimeType = "video/mp4";
var params = new Object();
params.value1 = "test";
params.value2 = "param";

options.params = params;

ft.upload(path, "http://192.168.0.46/upload/upload.php",
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
console.log("Response = " + r.response);
alert("Response = " + r.response);
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
alert('Error uploading file ' + path + ': ' + error.code);
},
options);
alert(mediaFile.fullPath);
}
</script>
<script type="text/javascript" src="cordova.js"></script>
<div data-role="page">
<div data-role="header">
<h3>Welcome </h3>
</div>
<div data-role="main" class="ui-content">
<h3 style="text-align: center;">Input Your IMEI:</h3>
<input type="number"/>
<h3 style="text-align: center;"> yes?</h3>

<input type="radio" name="visit" value="YES" id="Video">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; YES
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="visit" value="NO" id="self">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NO
<br>
<h3 style="text-align: center;"> damage.</h3>
<input type="radio" name="damage" value="Physical">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Physical
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" name="damage" value="Water">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Water <br><br>
<h3 style="text-align: center;">Please give a breig description about the damage</h3><br>
<textarea rows="5" cols="10" style="resize:none"></textarea>
<div class="YES box"><input type="button" value="self analysis" hidden="true"></div>
<div class="NO box"> <button onclick="captureVideo();">Capture Video</button></div>

</div>
</div>
</body>
</html>


This is my php code..



<?php
print_r($_FILES);
$new_image_name = "r.mp4";
move_uploaded_file($_FILES["file"]["tmp_name"], $new_image_name);
?>


The uploadFile function is supposed to upload the file to the specified php file. but in my case the phonegap filetransfer is giving error code 1 which is file not found. I have alert the file path after capture which is same file to be uploaded. How is it throwing error code 1?







javascript php cordova phonegap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 1 '17 at 9:38









Tridev ChaudharyTridev Chaudhary

16118




16118













  • and how mediaFile.fullPath looks like?

    – jcesarmobile
    Jun 1 '17 at 9:41











  • file:///storage/emulated/0/DCIM/Camera/20170601_144112.mp4

    – Tridev Chaudhary
    Jun 1 '17 at 9:43











  • Read the plugin compatibility notes, fullPath is not supported github.com/apache/…

    – jcesarmobile
    Jun 1 '17 at 9:50



















  • and how mediaFile.fullPath looks like?

    – jcesarmobile
    Jun 1 '17 at 9:41











  • file:///storage/emulated/0/DCIM/Camera/20170601_144112.mp4

    – Tridev Chaudhary
    Jun 1 '17 at 9:43











  • Read the plugin compatibility notes, fullPath is not supported github.com/apache/…

    – jcesarmobile
    Jun 1 '17 at 9:50

















and how mediaFile.fullPath looks like?

– jcesarmobile
Jun 1 '17 at 9:41





and how mediaFile.fullPath looks like?

– jcesarmobile
Jun 1 '17 at 9:41













file:///storage/emulated/0/DCIM/Camera/20170601_144112.mp4

– Tridev Chaudhary
Jun 1 '17 at 9:43





file:///storage/emulated/0/DCIM/Camera/20170601_144112.mp4

– Tridev Chaudhary
Jun 1 '17 at 9:43













Read the plugin compatibility notes, fullPath is not supported github.com/apache/…

– jcesarmobile
Jun 1 '17 at 9:50





Read the plugin compatibility notes, fullPath is not supported github.com/apache/…

– jcesarmobile
Jun 1 '17 at 9:50












2 Answers
2






active

oldest

votes


















1














Try this, you might be able to use this



http://findnerd.com/list/view/Capturing-and-Uploading-Video-to-PHP-Server-in-Cordova/9398/



From the site:




If you want to send image as base64 string you can change destination
type to Camera.DestinationType.DATA_URL and you can send imageData to
server via ajax call. or, if you want to send as file array then keep
the same destination type to camera.DestinationType.FILE_URI and use
cordova file plugin to send file data in server:




var options = new FileUploadOptions();
options.fileKey="tickitFile";
options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
options.contentType = "multipart/form-data";
options.chunkedMode = false;
options.mimeType="image/jpeg";
options.httpMethod="POST";
options.headers = {
Connection: "close"
};


var ft = new FileTransfer();


ft.upload(imageData, PHP_URL, win, fail, options);
function win(r) {
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
console.log(JSON.stringify(error));
}





share|improve this answer

































    0














    you can try this below :



    function upload(file){

    var fd = new FormData();
    fd.append("dir", dir);
    fd.append("file", file);
    var xhr = new XMLHttpRequest();

    xhr.open('POST', 'upload.php', true);
    xhr.send(fd);


    xhr.onreadystatechange = function() {

    if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

    //alert(xhr.responseText);
    var message = xhr.responseText;
    message=message.trim();

    if ( message != 0)
    {
    //alert(message);
    }
    }
    };
    }


    and the php file :



    <?php
    if (isset($_FILES["file"]["name"])) {

    $destination = $_POST["dir"];

    $name = $_FILES["file"]["name"];
    $tmp_name = $_FILES['file']['tmp_name'];
    $error = $_FILES['file']['error'];



    //echo $name;
    //echo $tmp_name;
    //echo $error;

    move_uploaded_file($_FILES['file']['tmp_name'], $destination.$name);

    }

    echo "File transfer completed";
    ?>




    XHR POST has no size limit, but you're sending data to PHP which has a size limit ;) Create the following php-file and open it in a browser:




    Now search for the variable "post_max_size", this variable limits the maximum data that can be sent to PHP (but it can be changed in the php.ini)





    My upload function and my php file works perfectly for an input file like :



    var obj=document.getElementById("inputfile");

    var len = obj.files.length;

    for (i=0; i<=len; i++){

    upload( obj.files[i] );
    }


    for me the problem is the output type of your capturevideo() function or an error in captureSuccess(mediaFiles): try to change for smomething like this below :



     function captureSuccess(mediaFiles) {
    var i, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
    uploadFile(mediaFiles[i].fullPath);
    }
    }





    share|improve this answer


























    • i am not getting any error but to which location is the file getting moved? because i cant see it in my folder

      – Tridev Chaudhary
      Jun 1 '17 at 10:05











    • alert gives me the path of video in my mobile

      – Tridev Chaudhary
      Jun 1 '17 at 10:06











    • The file is moved to the $destination folder you need to set a JS var like : var dir = "your_path/"; or directly set the $destination in your php file instead of use a $ _POST ["dir"];

      – Aominé
      Jun 1 '17 at 10:06













    • Ne charge toujours pas

      – Tridev Chaudhary
      Jun 1 '17 at 10:12











    • what is the output type of your catpurevideo function ?

      – Aominé
      Jun 1 '17 at 11:41











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44303931%2fuploading-video-from-phonegap-to-php%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Try this, you might be able to use this



    http://findnerd.com/list/view/Capturing-and-Uploading-Video-to-PHP-Server-in-Cordova/9398/



    From the site:




    If you want to send image as base64 string you can change destination
    type to Camera.DestinationType.DATA_URL and you can send imageData to
    server via ajax call. or, if you want to send as file array then keep
    the same destination type to camera.DestinationType.FILE_URI and use
    cordova file plugin to send file data in server:




    var options = new FileUploadOptions();
    options.fileKey="tickitFile";
    options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
    options.contentType = "multipart/form-data";
    options.chunkedMode = false;
    options.mimeType="image/jpeg";
    options.httpMethod="POST";
    options.headers = {
    Connection: "close"
    };


    var ft = new FileTransfer();


    ft.upload(imageData, PHP_URL, win, fail, options);
    function win(r) {
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
    }
    function fail(error) {
    console.log(JSON.stringify(error));
    }





    share|improve this answer






























      1














      Try this, you might be able to use this



      http://findnerd.com/list/view/Capturing-and-Uploading-Video-to-PHP-Server-in-Cordova/9398/



      From the site:




      If you want to send image as base64 string you can change destination
      type to Camera.DestinationType.DATA_URL and you can send imageData to
      server via ajax call. or, if you want to send as file array then keep
      the same destination type to camera.DestinationType.FILE_URI and use
      cordova file plugin to send file data in server:




      var options = new FileUploadOptions();
      options.fileKey="tickitFile";
      options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
      options.contentType = "multipart/form-data";
      options.chunkedMode = false;
      options.mimeType="image/jpeg";
      options.httpMethod="POST";
      options.headers = {
      Connection: "close"
      };


      var ft = new FileTransfer();


      ft.upload(imageData, PHP_URL, win, fail, options);
      function win(r) {
      console.log("Response = " + r.response);
      console.log("Sent = " + r.bytesSent);
      }
      function fail(error) {
      console.log(JSON.stringify(error));
      }





      share|improve this answer




























        1












        1








        1







        Try this, you might be able to use this



        http://findnerd.com/list/view/Capturing-and-Uploading-Video-to-PHP-Server-in-Cordova/9398/



        From the site:




        If you want to send image as base64 string you can change destination
        type to Camera.DestinationType.DATA_URL and you can send imageData to
        server via ajax call. or, if you want to send as file array then keep
        the same destination type to camera.DestinationType.FILE_URI and use
        cordova file plugin to send file data in server:




        var options = new FileUploadOptions();
        options.fileKey="tickitFile";
        options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
        options.contentType = "multipart/form-data";
        options.chunkedMode = false;
        options.mimeType="image/jpeg";
        options.httpMethod="POST";
        options.headers = {
        Connection: "close"
        };


        var ft = new FileTransfer();


        ft.upload(imageData, PHP_URL, win, fail, options);
        function win(r) {
        console.log("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
        }
        function fail(error) {
        console.log(JSON.stringify(error));
        }





        share|improve this answer















        Try this, you might be able to use this



        http://findnerd.com/list/view/Capturing-and-Uploading-Video-to-PHP-Server-in-Cordova/9398/



        From the site:




        If you want to send image as base64 string you can change destination
        type to Camera.DestinationType.DATA_URL and you can send imageData to
        server via ajax call. or, if you want to send as file array then keep
        the same destination type to camera.DestinationType.FILE_URI and use
        cordova file plugin to send file data in server:




        var options = new FileUploadOptions();
        options.fileKey="tickitFile";
        options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
        options.contentType = "multipart/form-data";
        options.chunkedMode = false;
        options.mimeType="image/jpeg";
        options.httpMethod="POST";
        options.headers = {
        Connection: "close"
        };


        var ft = new FileTransfer();


        ft.upload(imageData, PHP_URL, win, fail, options);
        function win(r) {
        console.log("Response = " + r.response);
        console.log("Sent = " + r.bytesSent);
        }
        function fail(error) {
        console.log(JSON.stringify(error));
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 14 '18 at 14:01









        matt

        1,1252824




        1,1252824










        answered Nov 14 '18 at 13:14









        dev ddev d

        262




        262

























            0














            you can try this below :



            function upload(file){

            var fd = new FormData();
            fd.append("dir", dir);
            fd.append("file", file);
            var xhr = new XMLHttpRequest();

            xhr.open('POST', 'upload.php', true);
            xhr.send(fd);


            xhr.onreadystatechange = function() {

            if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

            //alert(xhr.responseText);
            var message = xhr.responseText;
            message=message.trim();

            if ( message != 0)
            {
            //alert(message);
            }
            }
            };
            }


            and the php file :



            <?php
            if (isset($_FILES["file"]["name"])) {

            $destination = $_POST["dir"];

            $name = $_FILES["file"]["name"];
            $tmp_name = $_FILES['file']['tmp_name'];
            $error = $_FILES['file']['error'];



            //echo $name;
            //echo $tmp_name;
            //echo $error;

            move_uploaded_file($_FILES['file']['tmp_name'], $destination.$name);

            }

            echo "File transfer completed";
            ?>




            XHR POST has no size limit, but you're sending data to PHP which has a size limit ;) Create the following php-file and open it in a browser:




            Now search for the variable "post_max_size", this variable limits the maximum data that can be sent to PHP (but it can be changed in the php.ini)





            My upload function and my php file works perfectly for an input file like :



            var obj=document.getElementById("inputfile");

            var len = obj.files.length;

            for (i=0; i<=len; i++){

            upload( obj.files[i] );
            }


            for me the problem is the output type of your capturevideo() function or an error in captureSuccess(mediaFiles): try to change for smomething like this below :



             function captureSuccess(mediaFiles) {
            var i, len;
            for (i = 0, len = mediaFiles.length; i < len; i += 1) {
            uploadFile(mediaFiles[i].fullPath);
            }
            }





            share|improve this answer


























            • i am not getting any error but to which location is the file getting moved? because i cant see it in my folder

              – Tridev Chaudhary
              Jun 1 '17 at 10:05











            • alert gives me the path of video in my mobile

              – Tridev Chaudhary
              Jun 1 '17 at 10:06











            • The file is moved to the $destination folder you need to set a JS var like : var dir = "your_path/"; or directly set the $destination in your php file instead of use a $ _POST ["dir"];

              – Aominé
              Jun 1 '17 at 10:06













            • Ne charge toujours pas

              – Tridev Chaudhary
              Jun 1 '17 at 10:12











            • what is the output type of your catpurevideo function ?

              – Aominé
              Jun 1 '17 at 11:41
















            0














            you can try this below :



            function upload(file){

            var fd = new FormData();
            fd.append("dir", dir);
            fd.append("file", file);
            var xhr = new XMLHttpRequest();

            xhr.open('POST', 'upload.php', true);
            xhr.send(fd);


            xhr.onreadystatechange = function() {

            if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

            //alert(xhr.responseText);
            var message = xhr.responseText;
            message=message.trim();

            if ( message != 0)
            {
            //alert(message);
            }
            }
            };
            }


            and the php file :



            <?php
            if (isset($_FILES["file"]["name"])) {

            $destination = $_POST["dir"];

            $name = $_FILES["file"]["name"];
            $tmp_name = $_FILES['file']['tmp_name'];
            $error = $_FILES['file']['error'];



            //echo $name;
            //echo $tmp_name;
            //echo $error;

            move_uploaded_file($_FILES['file']['tmp_name'], $destination.$name);

            }

            echo "File transfer completed";
            ?>




            XHR POST has no size limit, but you're sending data to PHP which has a size limit ;) Create the following php-file and open it in a browser:




            Now search for the variable "post_max_size", this variable limits the maximum data that can be sent to PHP (but it can be changed in the php.ini)





            My upload function and my php file works perfectly for an input file like :



            var obj=document.getElementById("inputfile");

            var len = obj.files.length;

            for (i=0; i<=len; i++){

            upload( obj.files[i] );
            }


            for me the problem is the output type of your capturevideo() function or an error in captureSuccess(mediaFiles): try to change for smomething like this below :



             function captureSuccess(mediaFiles) {
            var i, len;
            for (i = 0, len = mediaFiles.length; i < len; i += 1) {
            uploadFile(mediaFiles[i].fullPath);
            }
            }





            share|improve this answer


























            • i am not getting any error but to which location is the file getting moved? because i cant see it in my folder

              – Tridev Chaudhary
              Jun 1 '17 at 10:05











            • alert gives me the path of video in my mobile

              – Tridev Chaudhary
              Jun 1 '17 at 10:06











            • The file is moved to the $destination folder you need to set a JS var like : var dir = "your_path/"; or directly set the $destination in your php file instead of use a $ _POST ["dir"];

              – Aominé
              Jun 1 '17 at 10:06













            • Ne charge toujours pas

              – Tridev Chaudhary
              Jun 1 '17 at 10:12











            • what is the output type of your catpurevideo function ?

              – Aominé
              Jun 1 '17 at 11:41














            0












            0








            0







            you can try this below :



            function upload(file){

            var fd = new FormData();
            fd.append("dir", dir);
            fd.append("file", file);
            var xhr = new XMLHttpRequest();

            xhr.open('POST', 'upload.php', true);
            xhr.send(fd);


            xhr.onreadystatechange = function() {

            if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

            //alert(xhr.responseText);
            var message = xhr.responseText;
            message=message.trim();

            if ( message != 0)
            {
            //alert(message);
            }
            }
            };
            }


            and the php file :



            <?php
            if (isset($_FILES["file"]["name"])) {

            $destination = $_POST["dir"];

            $name = $_FILES["file"]["name"];
            $tmp_name = $_FILES['file']['tmp_name'];
            $error = $_FILES['file']['error'];



            //echo $name;
            //echo $tmp_name;
            //echo $error;

            move_uploaded_file($_FILES['file']['tmp_name'], $destination.$name);

            }

            echo "File transfer completed";
            ?>




            XHR POST has no size limit, but you're sending data to PHP which has a size limit ;) Create the following php-file and open it in a browser:




            Now search for the variable "post_max_size", this variable limits the maximum data that can be sent to PHP (but it can be changed in the php.ini)





            My upload function and my php file works perfectly for an input file like :



            var obj=document.getElementById("inputfile");

            var len = obj.files.length;

            for (i=0; i<=len; i++){

            upload( obj.files[i] );
            }


            for me the problem is the output type of your capturevideo() function or an error in captureSuccess(mediaFiles): try to change for smomething like this below :



             function captureSuccess(mediaFiles) {
            var i, len;
            for (i = 0, len = mediaFiles.length; i < len; i += 1) {
            uploadFile(mediaFiles[i].fullPath);
            }
            }





            share|improve this answer















            you can try this below :



            function upload(file){

            var fd = new FormData();
            fd.append("dir", dir);
            fd.append("file", file);
            var xhr = new XMLHttpRequest();

            xhr.open('POST', 'upload.php', true);
            xhr.send(fd);


            xhr.onreadystatechange = function() {

            if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {

            //alert(xhr.responseText);
            var message = xhr.responseText;
            message=message.trim();

            if ( message != 0)
            {
            //alert(message);
            }
            }
            };
            }


            and the php file :



            <?php
            if (isset($_FILES["file"]["name"])) {

            $destination = $_POST["dir"];

            $name = $_FILES["file"]["name"];
            $tmp_name = $_FILES['file']['tmp_name'];
            $error = $_FILES['file']['error'];



            //echo $name;
            //echo $tmp_name;
            //echo $error;

            move_uploaded_file($_FILES['file']['tmp_name'], $destination.$name);

            }

            echo "File transfer completed";
            ?>




            XHR POST has no size limit, but you're sending data to PHP which has a size limit ;) Create the following php-file and open it in a browser:




            Now search for the variable "post_max_size", this variable limits the maximum data that can be sent to PHP (but it can be changed in the php.ini)





            My upload function and my php file works perfectly for an input file like :



            var obj=document.getElementById("inputfile");

            var len = obj.files.length;

            for (i=0; i<=len; i++){

            upload( obj.files[i] );
            }


            for me the problem is the output type of your capturevideo() function or an error in captureSuccess(mediaFiles): try to change for smomething like this below :



             function captureSuccess(mediaFiles) {
            var i, len;
            for (i = 0, len = mediaFiles.length; i < len; i += 1) {
            uploadFile(mediaFiles[i].fullPath);
            }
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 1 '17 at 11:49

























            answered Jun 1 '17 at 9:45









            AominéAominé

            19510




            19510













            • i am not getting any error but to which location is the file getting moved? because i cant see it in my folder

              – Tridev Chaudhary
              Jun 1 '17 at 10:05











            • alert gives me the path of video in my mobile

              – Tridev Chaudhary
              Jun 1 '17 at 10:06











            • The file is moved to the $destination folder you need to set a JS var like : var dir = "your_path/"; or directly set the $destination in your php file instead of use a $ _POST ["dir"];

              – Aominé
              Jun 1 '17 at 10:06













            • Ne charge toujours pas

              – Tridev Chaudhary
              Jun 1 '17 at 10:12











            • what is the output type of your catpurevideo function ?

              – Aominé
              Jun 1 '17 at 11:41



















            • i am not getting any error but to which location is the file getting moved? because i cant see it in my folder

              – Tridev Chaudhary
              Jun 1 '17 at 10:05











            • alert gives me the path of video in my mobile

              – Tridev Chaudhary
              Jun 1 '17 at 10:06











            • The file is moved to the $destination folder you need to set a JS var like : var dir = "your_path/"; or directly set the $destination in your php file instead of use a $ _POST ["dir"];

              – Aominé
              Jun 1 '17 at 10:06













            • Ne charge toujours pas

              – Tridev Chaudhary
              Jun 1 '17 at 10:12











            • what is the output type of your catpurevideo function ?

              – Aominé
              Jun 1 '17 at 11:41

















            i am not getting any error but to which location is the file getting moved? because i cant see it in my folder

            – Tridev Chaudhary
            Jun 1 '17 at 10:05





            i am not getting any error but to which location is the file getting moved? because i cant see it in my folder

            – Tridev Chaudhary
            Jun 1 '17 at 10:05













            alert gives me the path of video in my mobile

            – Tridev Chaudhary
            Jun 1 '17 at 10:06





            alert gives me the path of video in my mobile

            – Tridev Chaudhary
            Jun 1 '17 at 10:06













            The file is moved to the $destination folder you need to set a JS var like : var dir = "your_path/"; or directly set the $destination in your php file instead of use a $ _POST ["dir"];

            – Aominé
            Jun 1 '17 at 10:06







            The file is moved to the $destination folder you need to set a JS var like : var dir = "your_path/"; or directly set the $destination in your php file instead of use a $ _POST ["dir"];

            – Aominé
            Jun 1 '17 at 10:06















            Ne charge toujours pas

            – Tridev Chaudhary
            Jun 1 '17 at 10:12





            Ne charge toujours pas

            – Tridev Chaudhary
            Jun 1 '17 at 10:12













            what is the output type of your catpurevideo function ?

            – Aominé
            Jun 1 '17 at 11:41





            what is the output type of your catpurevideo function ?

            – Aominé
            Jun 1 '17 at 11:41


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44303931%2fuploading-video-from-phonegap-to-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues