将用户ID添加到PhoneGap文件上传 [英] Add user ID to PhoneGap File Upload

查看:182
本文介绍了将用户ID添加到PhoneGap文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PhoneGap API上传照片。 FileTransfer对象基本上是我想要的,因为我想上传一张照片,但是我想包括一些关于用户的基本信息,比如他们的用户ID,这样我就可以把它存储为他们的。我的代码如下,这基本上来自 PhoneGap API ,但添加了

 < html>< head>< script> function uploadPhotoandID(imageURI,userID) {
var options = new FileUploadOptions();
options.fileKey =file;
options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+ 1);
options.mimeType =image / jpeg;

var params = new Object();
params.value1 =test;
params.value2 =param;

options.params = params;

var ft = new FileTransfer();
ft.upload(imageURI,http://some.server.com/upload.php,win,fail,options);
ft.upload(userID,http://some.server.com/upload.php,win,fail,options);
}< / script>< / head>
< body>< button onclick =uploadPhotoandID(imageURI,userID)>点击我< /按钮>< / body< / html>

我是否需要HTML中的函数中的那些参数?它是否能够检索这些变量,即使他们在头文件中的脚本?



如果您看到任何其他错误,请让我知道! b $ b

解决方案

正因如此,所有你想要做的是:而不是:

  var params = new Object(); 
params.value1 =test;
params.value2 =param;

options.params = params;

您可以:

  var params = new Object(); 
params。 userID = userID;

options.params = params;

现在您不必进行两次上传调用。 userID参数可用:
$ b $ $ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

p>

在您的PHP脚本中。


I want to upload a photo using the PhoneGap API. The FileTransfer object is basically what I want because I want to upload a photo but then I want to include some basic information about the user as well such as their user ID so that I can store it as their's. My code is as follows and this is basically coming from the PhoneGap API but with my additions

<html><head><script>function uploadPhotoandID(imageURI, userID) {
        var options = new FileUploadOptions();
        options.fileKey="file";
        options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
        options.mimeType="image/jpeg";

        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;

        var ft = new FileTransfer();
        ft.upload(imageURI, "http://some.server.com/upload.php", win, fail, options);
        ft.upload(userID, "http://some.server.com/upload.php", win, fail, options);
    }</script></head>
    <body><button onclick="uploadPhotoandID(imageURI, userID)">Click me</button></body</html>

Do I need those parameters in the function in HTML like that? and is it able to retrieve those variables even though they are in the script in the header?

If you see any other errors please let me know!

解决方案

Right so all you want to do is instead of:

var params = new Object();
params.value1 = "test";
params.value2 = "param";

options.params = params;

you would:

var params = new Object();
params. userID = userID;

options.params = params;

Now you don't have to make two calls to "upload". The userID parameter will be available as:

$_POST["userID"]

in your PHP script.

这篇关于将用户ID添加到PhoneGap文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆