2012-07-16 1 views
2

이 플러그인은 페이지로드시blueimproot/server/php/files에있는 이미지 파일을 읽습니다. 데이터베이스에서 레코드를 읽고 '다운로드'HTML 구조를 내 사용자 지정 구조로 바꿔야합니다. 이 플러그인을 통해 이미지를 업로드/제거 할 때 영향을받는 카탈로그 제품을 보여 드리고자합니다.Blueimp jQuery File Upload 데이터베이스와 통합

지금까지 이런 짓을했습니다

  • 내가 데이터베이스에서 레코드를 검색 할 blueimproot/서버/PHP/upload.class.phppublic function get() { ... }을 변경했습니다. 이 함수는 json 객체를 반환합니다. 내가 어디에 모르는

    switch ($_SERVER['REQUEST_METHOD']) { 
        ... 
        case 'GET': 
         $upload_handler->get(); 
         break; 
        ... 
    

    }

:

public function get() { 
    /* default code of Blueimp 
    $file_name = isset($_REQUEST['file']) ? 
    basename(stripslashes($_REQUEST['file'])) : null; 
    if ($file_name) { 
     $info = $this->get_file_object($file_name); 
    } else { 
     $info = $this->get_file_objects(); 
    } 

    header('Content-type: application/json'); 
    echo json_encode($info); 
    */ 

    include_once('../../../../connection.php'); 

    $id_cat = $_REQUEST['catid']; 
    $query = "SELECT id, name, price, img_path FROM products WHERE id_cat = $id_cat ORDER BY id"; 
    $prods = mysql_query($query); 

    $prod_arr = array(); 
    while($prod = mysql_fetch_assoc($prods)) { 
     $prod_arr[] = $prod; 
    } 

    header('Content-type: application/json'); 
    echo json_encode($info); 
    } 
  • 는 그 기능/php에blueimproot/서버 index.php를에서 호출 발견 반환 된 json 객체는 UI에 표시되도록 처리됩니다. 2 일이 지났지 만 그 기능 흐름을 추적 할 수는 없습니다. 도와주세요. 감사.

    원래 온라인 데모 : http://blueimp.github.com/jQuery-File-Upload/

    원래 플러그인 다운로드 : https://github.com/blueimp/jQuery-File-Upload/downloads

  • +0

    그래서 특정 사용자가 업로드 한 파일 만 나열/필터링하고 싶습니까? 편집 한 내용을 표시하거나 전체 코드에 링크하거나 반향하는 JSON 객체의 샘플을 제공하면 많은 도움이됩니다. –

    +0

    아니요, 데이터베이스에서 제품을 검색하려고합니다. 각 제품마다 이미지 경로가 있습니다. 이 플러그인을 통해 이미지 파일을 추가/제거하면 데이터베이스와 UI에 영향을 주어야합니다. 스레드를 업데이트했습니다. –

    +0

    나는 본다. 예상되는 결과는 무엇입니까? 각 제품에 대해 여러 개의 이미지를 업로드하고 검색하고 싶습니까? 또는'img_path'에 저장된 하나의 이미지로 제한 하시겠습니까? 그리고 당신의 주요 어려움은 무엇입니까? 제품 페이지에 제품 이미지를 표시 하시겠습니까? –

    답변

    2
    public function get() { 
        /* 
        $file_name = isset($_REQUEST['file']) ? 
         basename(stripslashes($_REQUEST['file'])) : null; 
        if ($file_name) { 
         $info = $this->get_file_object($file_name); 
        } else { 
         $info = $this->get_file_objects(); 
        } 
        header('Content-type: application/json'); 
        echo json_encode($info); 
        */ 
         $id_cat = $_REQUEST['catid']; 
         $query = "SELECT id, name, price, img_path FROM products WHERE id_cat = $id_cat ORDER BY id"; 
         $prods = mysql_query($query); 
    
         $prod_arr = array(); 
         while($prod = mysql_fetch_assoc($prods)) { 
          //$prod_arr[] = $prod; 
    
          $file = new stdClass(); 
          $file->name = "";// here image name goes i do not find image name in your select query 
          $file->size = filesize($prod["img_path"]);// should be complete path 
          $file->url = $prod["img_path"];// should be relative path (http://localhost/images/234.jpg) 
          $file->thumbnail_url = $prod["img_path"]; // thumbnail path 
          $this->delete_type = "DELETE"; 
          $this->delete_url = ""; //here delete url you can delete image from database 
          array_push($prod_arr,$file); 
         } 
         header('Content-type: application/json'); 
        echo json_encode($prod_arr); 
    } 
    
    3

    나의 제안은 Network Tab in Firebug를 열고 server/php/index.php에 대한 GET 요청을 감시하는 것입니다. 특정 이벤트가 있은 후에 발생하면 더 자세하게 볼 수 있어야합니다. , https://github.com/blueimp/jQuery-File-Upload/wiki/Working-with-databases

    I 설정 업로드가 데이터베이스에 삽입되는이 WIKI 다음 main.js

    $('#fileupload').each(function() { 
        var that = this; 
        $.getJSON(this.action, function (result) { 
        if (result && result.length) { 
         $(that).fileupload('option', 'done') 
         .call(that, null, {result: result}); 
         } 
        }); 
        }); 
    } 
    
    2

    내가 소스 파일과 내가 찾은 유일한 GET 요청을 통해 볼 않았다이었다 다음과 같이 GET 함수를 변경했습니다.

      public function get() { 
           $uploads = $this->query_db(); 
           header('Content-type: application/json'); 
           echo json_encode($uploads); 
          } 
    

    과 my query_db는 다음과 같이 작동합니다.

      public function query_db() { 
        $uploads_array = array(); 
        $select_result = $this->query("SELECT * FROM `uploads` ORDER BY `file_name`") or die(mysql_error()); 
        while($query_results = mysql_fetch_object($select_result)) 
         { 
          $file = new stdClass(); 
          $file->id = $query_results->id; 
          $file->name = $query_results->file_name; 
          $file->size = $query_results->file_size; 
          $file->type = $query_results->file_type; 
          $file->url = "http://files.domain.com/".$query_results->file_name; 
          $file->thumbnail_url = "http://thumbnails.domain.com/".$query_results->file_name; 
          $file->delete_url = ""; 
          $file->delete_type = "DELETE"; 
          array_push($uploads_array,$file); 
         } 
        return $uploads_array; 
    }