简体   繁体   English

Phonegap黑莓手机照片上传服务器php脚本

[英]Phonegap blackberry photo upload server php script

There are many people asking questions related to this issue, but none are complete enough for me to solve my issue. 有很多人问与这个问题有关的问题,但没有一个完整的问题足以让我解决我的问题。

I have created a fully working HTML5 smartphone app, based on phonegap, for.. shudder... Blackberry that is sending data nicely to a remote MYSQL server using a server side php script. 我已经创建了一个基于phonegap的功能齐全的HTML5智能手机应用程序,用于.. shudder ...黑莓正在使用服务器端php脚本很好地将数据发送到远程MYSQL服务器。

However I want to give the option to also upload a photo as this is injury prevention, and hazards need photographing. 但是,我想提供一个选项来也上传照片,因为这是为了防止伤害,并且危害需要拍照。 This is a NON commercial product, it is a working example of modern smartphone technologies and to demonstrate how one app can be ported easily to various smartphones.. Blackberry is the common phone and has to be the prime example. 这是一种非商业产品,它是现代智能手机技术的一个有效示例,并演示了如何轻松地将一个应用程序移植到各种智能手机。.黑莓手机是常见的电话,必须是主要的示例。

I cannot for love nor money find any working examples of an app and a php server side script together. 我无法为爱或金钱而找不到应用程序和php服务器端脚本的任何有效示例。

The example I have extracted from the CORDOVA example file takes a picture, and I can see the generated thumbnail in my app, and that bit is all sweet (based on all code you see below), but I dont know what I need to program for my upload.php to do something. 我从CORDOVA示例文件中提取的示例拍摄了一张图片,并且可以在我的应用程序中看到生成的缩略图,并且这一切都很好(基于下面看到的所有代码),但是我不知道我需要编程什么为我的upload.php做些事情。 Everything I try just fails with error code 3 and 1.. 我尝试的所有操作均失败,并显示错误代码3和1.。

Here is the important code for the webapp. 这是webapp的重要代码。

HTML 的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 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' } 
                });
        }
    }

The server Id above is correct (it is the proper translation of my own development server so I am not using localhost, as I need this to be accurate). 上面的服务器ID是正确的(这是我自己的开发服务器的正确翻译,因此我不使用localhost,因为我需要此信息才是准确的)。 Everything you see with the exception of the server IP is vanilla, out the box, unaltered working example from phonegap. 除了服务器IP之外,您看到的所有内容都是原始的,可以直接使用,这是phonegap不变的工作示例。 The phone is one the same 192 network and defintaly tries to run whatever upload.php I try 手机是相同的192网络之一,并最终尝试运行我尝试的任何upload.php

Basically I want to take this file, and using the upload.php file move it to 基本上,我想获取此文件,然后使用upload.php文件将其移至

http : // 192.168.1.91/injury/sample_images/xxxx.jpg (spacing http as not sure how to stop it linking) http:// 192.168.1.91/injury/sample_images/xxxx.jpg(将http间距设置为不确定如何阻止其链接)

I have checked rights they are all ok, and my config.html has allow all domains 我已经检查了权限,它们都还不错,而我的config.html允许所有域

can anyone please put me out my misery and give me an example upload.php that will use the upload code above and just do something with the camera image. 任何人都可以请我摆脱困境,并举一个例子upload.php,它将使用上面的上传代码,并对相机图像做一些处理。

Once I can get a working example, I can break down exactly what is happening and start the learning process. 一旦得到一个可行的例子,我就可以准确地分解正在发生的事情并开始学习过程。

Alternativly if someone can provide a working app.. with both app and server side code to use as a tutorial, I am happy to do the studying involved. 或者,如果有人可以提供可运行的应用程序,同时提供应用程序和服务器端代码以用作教程,那么我很乐意参与其中的学习。

Many many thanks in advance for any time people give to this. 在此之前,很多人在此表示感谢。 I am at my wits end, and getting myself in a right muddle when I should be able to get this done. 我精打细算,在应该能够完成任务的时候让自己陷入混乱。

I decided to use a posting method of the base64 string. 我决定使用base64字符串的发布方法。 I did find however that in this case it was more likely to be the settings on my development server that were the likely cause. 但是,我确实发现,在这种情况下,很可能是我的开发服务器上的设置引起了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM