2014-04-11 54 views
-1

這裏是我的JavaScript代碼。如何使用uploadify將發佈數據發送到服務器端

$(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'} 
    ); 
} 

    }); 
}); 

此代碼只能發送靜態數據,但不能形成我不知道的數據。我只是卡住請幫助。

+0

您可以上傳文件嗎? – nithi

+0

@nithi是我可以上傳,但問題是,我不能將數據發佈到服務器端 – sach9949

回答

0
<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用於將POST_ID發送到PHP文件

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'"); 

} 
+0

非常感謝你的重播@nithi ..但它不起作用 – sach9949

+0

不工作意味着你有任何錯誤? – nithi

+0

其傳遞空值 – sach9949

0

的第一件事是,你應該從 'GET' 到 'POST' 改變你的方法,只是像

method = 'post' 

您可以通過發送到服務器端通過formData屬性的任何值,然後更新它「o nUploadStart「事件uploadify 您的最終代碼看起來像

$(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'}); 
     }, 

    } 

    }); 
}); 
相關問題