这个插件在页面加载读取blueimproot /服务器/ PHP /文件的图像文件。 我需要读取数据库中的记录,并更换“下载” HTML结构,我的自定义结构。 我想说明的目录产品,哪些项目上载/过这个插件删除图像的影响。
我到目前为止已经做到了这一点:
我改变了public function get() { ... }
在blueimproot /服务器/ PHP / upload.class.php来检索数据库中的记录。 这个函数返回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); }
我发现功能是从的index.php在blueimproot /服务器/ 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
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);
}
我的建议是,以开拓在Firebug的网络选项卡 ,并注意任何GET请求到server/php/index.php
。 如果一个特定事件发生后,然后你就会有你应该看看其中一个更好的主意。
我也期待通过源文件和唯一的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});
}
});
});
}
在此之后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;
}