Blueimp jQuery File Upload Integrated with Database

后端 未结 3 1080
孤城傲影
孤城傲影 2021-02-06 19:17

This plugin reads image files on blueimproot/server/php/files on page load. I need to read records from database, and replace \'download\' HTML structure with m

相关标签:
3条回答
  • 2021-02-06 19:49

    Following this 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:

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

    and my query_db function as follows:

             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;
    }
    
    0 讨论(0)
  • 2021-02-06 19:50

    My suggestion is to open up the Network Tab in Firebug and watch for any GET requests to server/php/index.php. 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

    $('#fileupload').each(function () {
      var that = this;
      $.getJSON(this.action, function (result) {
        if (result && result.length) {
          $(that).fileupload('option', 'done')
            .call(that, null, {result: result});
            }
        });
      });
    }
    
    0 讨论(0)
  • 2021-02-06 19:51
     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);
    }
    
    0 讨论(0)
提交回复
热议问题