0

我正在尝试在此页面上实现示例代码:

http://docs.phonegap.com/en/2.9.0/cordova_media_capture_capture.md.html#CaptureImageOptions

在 capture.capture.Video 下(完整示例)

我已将“cordova-xxxjs”更改为“cordova.js”(这似乎是该发行版命名文件的方式)并将服务器更改为我的本地 Mac。

我可以从同一网络上的另一台 PC 将视频文件上传到服务器,但是当我在我的系留 iPhone 4S (6.1.3) 上从 Xcode 运行此代码时,我可以看到文件被临时写入 /private/var/tmp / 文件夹,但它没有移动到 webserver 文件夹;它就消失了。(当我从另一台 PC 上执行此操作时,我可以看到它是临时写入的,然后成功移动并重命名。)

这是该示例页面中的代码:

<!DOCTYPE html>
<html>
<head>
    <title>Capture Video</title>

    <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
    <script type="text/javascript" charset="utf-8" src="json2.js"></script>
    <script type="text/javascript" charset="utf-8">

        // Called when capture operation is finished
        //
        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: 2});
        }

        // Upload files to server
        function uploadFile(mediaFile) {
            var ft = new FileTransfer(),
            path = mediaFile.fullPath,
            name = mediaFile.name;

            ft.upload(path,
                      "http://192.168.0.3/~me/index.php",
                      function(result) {
                      console.log('Upload success: ' + result.responseCode);
                      console.log(result.bytesSent + ' bytes sent');
                      },
                      function(error) {
                      console.log('Error uploading file ' + path + ': ' + error.code);
                      },
                      { fileName: name });
        }

        </script>
</head>
<body>
    <button onclick="captureVideo();">Capture Video</button> <br>
</body>
</html>

这是我的PHP:

<?php

if (!empty($_FILES))
{
$file_src = 'video/'.$_FILES['image']['name'];
if(move_uploaded_file($_FILES['image']['tmp_name'], $file_src)):
echo 'Your file has been uploaded sucessfully';
else:
echo 'Error';
endif;
}
?>

知道我做错了什么吗?

谢谢

4

1 回答 1

0

好的,这段代码在网络服务器上工作:

<?php
$file_src = "new.mov";
move_uploaded_file($_FILES["file"]["tmp_name"], $file_src);
?>

...虽然我不确定 PHP 的哪个部分不起作用。

于 2013-08-16T16:59:42.313 回答