使用文档化的Phonegap示例和PHP无法正常上传视频

时间:2013-08-11 21:59:02

标签: php iphone video cordova

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

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

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

我已将“cordova-x.x.x.js”更改为“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;
}
?>

知道我做错了什么?

由于

1 个答案:

答案 0 :(得分:0)

好的,这段代码在网络服务器上运行:

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

......虽然我不确定PHP的哪个部分无效。