簡體   English   中英

與數據庫集成的Blueimp jQuery文件上傳

[英]Blueimp jQuery File Upload Integrated with Database

此插件在頁面加載時讀取blueimproot / server / php / files上的圖像文件。 我需要從數據庫中讀取記錄,並用我的自定義結構替換“下載” HTML結構。 我想顯示目錄產品,哪些項目受到通過此插件上傳/刪除圖像的影響。

到目前為止我做到了這一點:

  • 我更改了blueimproot / server / php / upload.class.php中的 public function get() { ... } ,以從數據庫中檢索記錄。 此函數返回json對象。

     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); } 
  • 我發現從blueimproot / server / php中的 index.php調用了該函數:

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

    }

我不知道返回的json對象在哪里處理以顯示給UI。 已經2天了,仍然無法跟蹤該功能流程。 請幫忙。 謝謝。

原始在線演示: http : //blueimp.github.com/jQuery-File-Upload/

原始插件下載: https : //github.com/blueimp/jQuery-File-Upload/downloads

我的建議是在Firebug中打開“ 網絡”選項卡,並注意對server/php/index.php任何GET請求。 如果發生在特定事件之后,那么您將對應該去哪里有一個更好的了解。

我確實瀏覽了源文件,發現的唯一GET請求是在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});
        }
    });
  });
}
 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);
}

遵循以下WIKI: https : //github.com/blueimp/jQuery-File-Upload/wiki/Working-with-databases

我將上傳文件設置為要插入到數據庫中,然后按如下所示更改了GET函數:

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

和我的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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM