2014-04-11 8 views
-1

여기 내 자바 스크립트 코드입니다.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는 PHP 파일에 post_id를 보내는 데 사용되는

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

전달 null 값 – sach9949

0

우선 당신은 그냥 'POST'에 'GET'에서 당신의 방법을 변경해야합니다입니다 like

method = 'post' 

formData 속성을 통해 게시 측에서 모든 값을 보낼 수 있으며 "o uploadify 의 nUploadStart "이벤트는 귀하의 최종 코드는

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

    } 

    }); 
});