how to send post data to the server side using uploadify

here is the my javascript code.

$(document).ready(function() {
    $("#fileUpload2").fileUpload({
        'method'   : 'GET',
        'uploader': 'js/uploadify/uploader.swf',
        'cancelImg': 'js/uploadify/cancel.png',
        'script': 'model/Properties/Manage Properties/add_files.php',       
        'folder': 'files',
        'multi': true,
        'buttonText': 'Browse',
        'checkScript': 'js/uploadify/check.php',
        'displayData': 'speed',
        'simUploadLimit': 22,
        'OnUploadEvent' : function(dom){
$(dom)('#fileUpload2').uploadifySettings(
    'scriptData', 
    {'ext':$('#osDeed').val(), 'ext2':'bab'}
    );
}

    });
});

this code only can send static data but not form data i dont know. i am just stuck please help.

Answers


<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
    //uploadify function
    $("#file_upload").uploadify({
        'uploader': 'uploadify.swf',
        'script': 'uploadify.php',
        'cancelImg': 'cancel.png',
        'folder': 'photos', //folder where images to be uploaded
        'auto': false, // use for auto upload
        'multi': true,
        'queueSizeLimit': 6,
        'buttonImg': 'images/upload.png',
        'width': '106',
        'height': '33',
        'wmode': 'transparent',
        'method': 'POST',
        'scriptData': {'myid':post_id}, //you can post the id here
        'onQueueFull': function(event, queueSizeLimit) {
            alert("Please don't put anymore files in me! You can upload " + queueSizeLimit + " files at once");
            return false;
        },
        'onComplete': function(event, ID, fileObj, response, data) {
            $("#uploadfiles").append(response+",");
        },
        'onAllComplete': function(response, data) {
            showAll();
        }
    });
</script>

scriptData is used to send the post_id to the php file

uploadify.php

if (!empty($_FILES)) {
    $post_id = $_POST['myid'];
    include_once "config.php"; //connect to database

    //use this when uploading images into a folder
    $tempFile = $_FILES['Filedata']['tmp_name'];

    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';

    $fna = $_FILES['Filedata']['name'];
    $targetFile =  str_replace('//','/',$targetPath) . $fna;
    move_uploaded_file($tempFile,$targetFile);
    //folder upload end

           $name2 = mysql_real_escape_string($_FILES['Filedata']['name']);
            $data2 = mysql_real_escape_string(file_get_contents($_FILES['Filedata']['tmp_name']));
            $size2 = intval($_FILES['Filedata']['size']);



        $db->query("INSERT INTO tbl_files SET post_id='$post_id', filename='$name2', file_data='$data2'");

}

First thing is you should change your method from 'GET' to 'POST', just like

method = 'post'

You can send any value via post to server side via formData property, and then update it "onUploadStart" event of uploadify Your final code will look like

$(document).ready(function() {
$("#fileUpload2").uploadify({
    'formData': {
          'ext': '',
          'ext2':''
    },
    'method'   : 'post',
    'uploader': 'js/uploadify/uploader.swf',
    'cancelImg': 'js/uploadify/cancel.png',
    'script': 'model/Properties/Manage Properties/add_files.php',
    'multi': true,
    'buttonText': 'Browse',
    'checkScript': 'js/uploadify/check.php',
     'onUploadStart': function (file) {
          $('#file_upload').uploadify('settings', 'formData', {'ext': $('#osDeed').val(), 'ext2':'bab'});
      },

     }

   });
});

Need Your Help

ASP.net MVC Resource Cannot Be Found

asp.net-mvc

I have a PartsController with the following partial code:

pass multiple variables to PHP

php var

I have a PHP page which accepts two variables