请求uploadify的帮助

时间:2011-02-16 23:16:20

标签: jquery

我需要jQuery uploadify的帮助。上传时,我想在表单中添加两个字段(名称和描述),我想在upload.php文件中接收这些数据。我认为这可以通过使用 scriptData 来完成,但我不明白如何发送这两个字段的值并在upload.php文件上接收。

<script type="text/javascript">

$(document).ready(function() {
    $("#fileUpload").fileUpload({
        'uploader': 'uploadify/uploader.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'uploadify/upload.php',
        'folder': 'files',
        'multi': false,
        'displayData': 'speed'
    });


});

</script>

这是上传表单,其中包含以下字段:

<fieldset>
        <h2>File Upload</h2>
        Name:<input type="text" name="name"><br />
        Description: <textarea rows="5" cols="20" name="desc" >Enter Description</textarea>:<br /> 
        <div id="fileUpload">You have a problem with your javascript</div>
        <a href="javascript:$('#fileUpload').fileUploadStart()">Start Upload</a> |  <a href="javascript:$('#fileUpload').fileUploadClearQueue()">Clear Queue</a>
        <p></p>
    </fieldset>

我将非常感谢任何帮助。

3 个答案:

答案 0 :(得分:0)

首先定义一个名为upload的函数:

<script type="text/javascript">

$(document).ready(function() {
    $("#fileUpload").fileUpload({
        'uploader': 'uploadify/uploader.swf',
        'cancelImg': 'uploadify/cancel.png',
        'script': 'uploadify/upload.php',
        'folder': 'files',
        'multi': false,
        'displayData': 'speed'
    });


});

    function upload(){
        var ipName = $("input[name='name']").val();
        var ipDesc = $("textarea[name='desc']").val();
        var data = {name:ipName, desc:ipDesc};
        $('#fileUpload').uploadifySettings("scriptData", data).fileUploadStart();
    }



</script>

然后将您的上传锚点更改为:

<fieldset>
        <h2>File Upload</h2>
        Name:<input type="text" name="name"><br />
        Description: <textarea rows="5" cols="20" name="desc" >Enter Description</textarea>:<br /> 
        <div id="fileUpload">You have a problem with your javascript</div>
            <a href="javascript:upload()">Start Upload</a> |
            <a href="javascript:$('#fileUpload').fileUploadClearQueue()">Clear Queue</a>
        <p></p>
    </fieldset>

答案 1 :(得分:0)

检查这个有些相关问题的答案:

Problem sending additional post data to server with uploadify

答案 2 :(得分:0)

我使用此功能,它工作正常。 StackOverflow中的某个人在不久前帮助了我。

$(function () {
        $('#file_upload').uploadify({
            'swf': 'js/uploadify/uploadify.swf',
            'uploader': 'Uploadify.ashx',
            'cancelImg': 'js/uploadify/uploadify-cancel.png',
            'multi': true,
            'auto': true,
            'onQueueComplete': function (uploads) {
                $author.val('');
                $title.val('');                    
            },
            'onUploadStart': function (file) {
                $("#file_upload").uploadify("settings", 'formData', { 'attFolder': 'Attach', 'idProject': $idProject, 'idClient': $idClient, 'auth': $author.val(), 'tit': $title.val() });
            }
        });
                                                                                                                                                                                                                                                                                                                                                                                                                                         标题                                                                                                                                                                                                                作者                                                                                                                                                                                                                             选择要上载的附件