问题描述
此插件在网页加载时读取 blueimproot / server / php / files 上的图片文件。我需要从数据库中读取记录,并用我的自定义结构替换下载HTML结构。我想显示目录产品,通过此插件上传/删除图像会影响哪些项目。
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.
到目前为止:
-
我在 blueimproot / server中更改了
public function get(){...}
/php/upload.class.php 从数据库中检索记录。此函数返回json对象。
I changed
public function get() { ... }
in blueimproot/server/php/upload.class.php to retrieve records from database. This function returns json object.
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);
}
我发现函数是从 index.php
I found that function is called from index.php in blueimproot/server/php:
switch ($_SERVER['REQUEST_METHOD']) {
...
case 'GET':
$upload_handler->get();
break;
...
}
我不知道返回的json对象处理到UI显示的位置。已经2天了,仍然无法跟踪该功能流。请帮忙。感谢。
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.
原创在线演示:
原创插件下载:
推荐答案
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);
}
这篇关于Blueimp jQuery文件上传与数据库集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!