Jeaf Gilbert
Jeaf Gilbert

Reputation: 11981

Blueimp jQuery File Upload Integrated with Database

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 my custom structure. I want to show catalog products, which items are affected by uploading/removing images through this plugin.

I've done this so far:

I don't know where the returned json object is processed to show to UI. Have been 2 days and still can't track that function flow. Please help. Thanks.

Original Online Demo: http://blueimp.github.com/jQuery-File-Upload/

Original Plugin Download: https://github.com/blueimp/jQuery-File-Upload/downloads

Upvotes: 2

Views: 9623

Answers (3)

Steven
Steven

Reputation: 21

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;
}

Upvotes: 2

Muhammad Arshad
Muhammad Arshad

Reputation: 107

 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);
}

Upvotes: 2

Baylor Rae'
Baylor Rae'

Reputation: 4010

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});
        }
    });
  });
}

Upvotes: 3

Related Questions