简体   繁体   English

与数据库集成的Blueimp jQuery文件上传

[英]Blueimp jQuery File Upload Integrated with Database

This plugin reads image files on blueimproot/server/php/files on page load. 此插件在页面加载时读取blueimproot / server / php / files上的图像文件。 I need to read records from database, and replace 'download' HTML structure with my custom structure. 我需要从数据库中读取记录,并用我的自定义结构替换“下载” HTML结构。 I want to show catalog products, which items are affected by uploading/removing images through this plugin. 我想显示目录产品,哪些项目受到通过此插件上传/删除图像的影响。

I've done this so far: 到目前为止我做到了这一点:

  • I changed public function get() { ... } in blueimproot/server/php/upload.class.php to retrieve records from database. 我更改了blueimproot / server / php / upload.class.php中的 public function get() { ... } ,以从数据库中检索记录。 This function returns json object. 此函数返回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); } 
  • I found that function is called from index.php in blueimproot/server/php : 我发现从blueimproot / server / php中的 index.php调用了该函数:

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

    } }

I don't know where the returned json object is processed to show to UI. 我不知道返回的json对象在哪里处理以显示给UI。 Have been 2 days and still can't track that function flow. 已经2天了,仍然无法跟踪该功能流程。 Please help. 请帮忙。 Thanks. 谢谢。

Original Online Demo: http://blueimp.github.com/jQuery-File-Upload/ 原始在线演示: http : //blueimp.github.com/jQuery-File-Upload/

Original Plugin Download: https://github.com/blueimp/jQuery-File-Upload/downloads 原始插件下载: https : //github.com/blueimp/jQuery-File-Upload/downloads

My suggestion is to open up the Network Tab in Firebug and watch for any GET requests to server/php/index.php . 我的建议是在Firebug中打开“ 网络”选项卡,并注意对server/php/index.php任何GET请求。 If it happens after a specific event then you'll have a better idea of where you should look. 如果发生在特定事件之后,那么您将对应该去哪里有一个更好的了解。

I did look through the source files and the only GET request I found was in main.js 我确实浏览了源文件,发现的唯一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);
}

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

I setup uploads to be inserted into a database, then i changed my GET function as follows: 我将上传文件设置为要插入到数据库中,然后按如下所示更改了GET函数:

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

and my query_db function as follows: 和我的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