【问题标题】:Phonegap blackberry photo upload server php scriptPhonegap黑莓照片上传服务器php脚本
【发布时间】:2012-09-25 20:24:11
【问题描述】:

有很多人提出与此问题相关的问题,但没有一个完整的足以让我解决我的问题。

我已经创建了一个基于 phonegap 的功能齐全的 HTML5 智能手机应用程序,用于......不寒而栗......黑莓使用服务器端 php 脚本将数据很好地发送到远程 MYSQL 服务器。

但是,我想提供上传照片的选项,因为这是预防伤害,危险需要拍照。这是一款非商业产品,它是现代智能手机技术的一个工作示例,并展示了如何将一个应用程序轻松移植到各种智能手机。黑莓是常见的手机,必须是最好的例子。

我找不到任何可以同时使用应用程序和 php 服务器端脚本的工作示例。

我从 CORDOVA 示例文件中提取的示例拍摄了一张照片,我可以在我的应用程序中看到生成的缩略图,这一切都很甜蜜(基于您在下面看到的所有代码),但我不知道我在做什么需要为我的upload.php 编程来做一些事情。我尝试的一切都失败了,错误代码为 3 和 1..

这里是 webapp 的重要代码。

HTML

    <h3>navigator.camera</h3>
<input type="button" value="Get Photo (Data)" onclick="capturePhoto();return false;" /> 
<input type="button" value="Get Photo (URI)" onclick="capturePhotoURI();return false;" /> 
<img style="display:none;width:120px;height:120px;" id="cameraImage" src="" />
<p id="uploadProgress"></p>
<input style="display:none;" id="uploadButton" type="button" value="Upload" onclick="uploadImage();return false;" />     

JAVASCRIPT

        function capturePhotoURI() {
        navigator.camera.getPicture(onCapturePhotoURISuccess, fail, 
            { destinationType: Camera.DestinationType.FILE_URI, quality: 50 });
    }

        function onCapturePhotoURISuccess(imageURI) {
        if (imageURI != null) {
            var smallImage = document.getElementById('cameraImage');
            var uploadButton = document.getElementById('uploadButton');

            // Unhide image elements
            smallImage.style.display = 'block';
            uploadButton.style.display = 'block';

            // Show the captured photo
            // The inline CSS rules are used to resize the image
            smallImage.src = imageURI;
        }
    }

        function uploadImage() {
        var smallImage = document.getElementById('cameraImage');
        if (smallImage.src && smallImage.src !== "") {
            var f = new FileTransfer();
            f.upload(
                // file path
                smallImage.src,
                // server URL - update to your own, and don't forget to 
                // include your domain in an access element in config.xml      
                "http://192.168.1.91/upload.php",
                // success callback
                function(result) {
                    document.getElementById('uploadProgress').innerHTML =
                        result.bytesSent + ' bytes sent';
                    alert(result.responseCode + ": " + result.response);
                },
                // error callback
                function(error) {
                    alert('error uploading file: ' + error.code);
                },
                // options
                { fileName: 'myImage.jpg', 
                  params: { 'username':'jtyberg' } 
                });
        }
    }

上面的服务器 ID 是正确的(它是我自己的开发服务器的正确翻译,所以我没有使用 localhost,因为我需要它是准确的)。除了服务器 IP 之外,您看到的所有内容都是普通的、开箱即用的、来自 phonegap 的未更改的工作示例。手机是同一个 192 网络,肯定会尝试运行我尝试的任何 upload.php

基本上我想拿这个文件,然后用upload.php文件把它移到

http : // 192.168.1.91/injury/sample_images/xxxx.jpg (将 http 隔开,不确定如何停止链接)

我检查了权限,它们都正常,我的 config.html 允许所有域

任何人都可以请我摆脱我的痛苦并给我一个示例upload.php,它将使用上面的上传代码并对相机图像做一些事情。

一旦我得到一个可行的例子,我就可以准确地分解正在发生的事情并开始学习过程。

如果有人可以提供一个可以工作的应用程序.. 将应用程序和服务器端代码用作教程,我很乐意进行相关研究。

非常感谢人们为此付出的任何时间。我束手无策,当我应该能够完成这项工作时,我陷入了正确的混乱之中。

【问题讨论】:

    标签: php html cordova blackberry camera


    【解决方案1】:

    我决定使用 base64 字符串的发布方法。但我确实发现,在这种情况下,很可能是我的开发服务器上的设置是可能的原因。

    【讨论】:

    • 我可以看看你的发帖方式吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 2012-10-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多