开发者

sending other input with $_FILES php

Im uploading a file using the following jquery..

function ajaxFileUpload(jobid) {
    $("#loading")
        .ajaxStart(function () {
        $(this).show();
    })
        .ajaxComplete(function () {
        $(this).hide();
    });

    $.ajaxFileUpload({
        url: 'addjobrpc.php',
        secureuri: false,
        jobID: jobid,
        fileElementId: 'fileToUpload',
        dataType: 'json',
        success: function (data, status) {
            $('#imageid').val(data.imageid);
            if (typeof (data.error) != 开发者_如何学C'undefined') {
                if (data.error != '') {
                    alert(data.error);
                } else {
                    alert(data.msg);
                }
            }
        },
        error: function (data, status, e) {
            alert(e);
        }
    })

    return false;

}

My form looks like this...

<form name="form" action="" method="POST" enctype="multipart/form-data">

I get the filename with $_FILES['fileToUpload']['name']; but how would I get a input that is not part of the file upload? For example Jobid is a hidden field but I can't seem to get the value in addjobrpc.

Thanks


The particular plugin you use seems to support only one specified file type of input element only rather than an entire form.

So I don't think you can pass along other elements.


I'm not familiar with this plugin but after taking a quick look at the source it seems that it is not capable of sending any additional POST data.

I'd suggest using this plugin instead, which allows you to do something like this:

new AjaxUpload('#upload_button_id', {
 action: 'addjobrpc.php',
 name: 'fileToUpload',
 // Additional data to send
 data: {
   jobID:jobid
 },
 // Submit file after selection
 autoSubmit: true,
 responseType: "json",
 onComplete: <success function goes here>
});

You can then use $_POST['jobID'] to retrieve the data on the server.


The way you have it set up then 'jobID' is sent as a parameter to ajaxFileUpload() but none of the jQuery AJAX functions know what to do with that. Though, given the code sample you provided I don't really see how any data gets sent to the server. Can you provide more code?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜