jQuery File Upload,获取和编辑保存在数据库中的数据 [英] jQuery File Upload, get and edit Data which is saved in DB
问题描述
已编辑
使用 jQuery文件上传文档,我可以使用MySQL DB中的图片 (请参见图片1 + 2)
With the jQuery File Upload Documentation I am able to save Data with the pictures in MySQL DB (see pic 1+2)
现在,我遇到的问题是如何取回数据.上载后,我想显示带有来自数据库的数据的图片,但是我找不到如何做到这一点.
Now where I'm stuck is how to retrieve the Data back. After the Upload I would like to show the pics with the Data from DB but there is nothing I can find how to do that.
如果有人知道如何编辑附加DB数据的json,或者我如何将其var_dump推向正确的方向,那就太棒了!我找不到在哪里创建json. json现在看起来像这样:
If anyone knows how to edit the json appending the DB data OR just how I can var_dump it just to push me in the right direction that would be awesome! I can not find where the json gets created. The json now looks like this:
{"files":[{
"name" : "02 (1).jpg",
"size" : 12508,
"type" : "image\/jpeg",
"url" : "http:\/\/localhost:8888\/server\/php\/files\/02%20%281%29.jpg",
"thumbnailUrl" : "http:\/\/localhost:8888\/server\/php\/files\/thumbnail\/02%20%281%29.jpg",
"deleteUrl" : "http:\/\/localhost:8888\/server\/php\/?file=02%20%281%29.jpg",
"deleteType" : "DELETE"
}]}
我想使它像这样:
{"files":[{
"name" : "02 (1).jpg",
"size" : 12508,
"type" : "image\/jpeg",
"url" : "http:\/\/localhost:8888\/server\/php\/files\/02%20%281%29.jpg",
"thumbnailUrl" : "http:\/\/localhost:8888\/server\/php\/files\/thumbnail\/02%20%281%29.jpg",
"deleteUrl" : "http:\/\/localhost:8888\/server\/php\/?file=02%20%281%29.jpg",
"deleteType" : "DELETE",
"titleDB" : "Title1",
"textDB" : "Lorem ipsum dolor...."
}]}
我尝试过(就像解释rAjA一样)并更改了以下内容
I tried (like rAjA explained) and changed the following
require('UploadHandler.php');
$upload_handler = new UploadHandler();
$response_enc = $this->upload_handler->initialize();
但是我收到一个错误消息:"JSON.parse:JSON数据后出现意外的非空白字符",为此我进行了搜索,发现了信息,但没有任何帮助.
But than I get an error saying "JSON.parse: unexpected non-whitespace character after JSON data" and I googeld for that and I found information but there is nothing which helped me.
任何人都可以帮助我解决这一问题,或者知道我在哪里可以找到该信息吗?谢谢!
Can anyone help me on this one or knows where I can find the Information? Thank you!
推荐答案
这将为您提供编辑来自uploadhandler库的json响应的基本思想,
This will give you the basic idea of editing the json response from uploadhandler library,
已编辑
在您的uploadhandler.php库中,更改此行,以使其返回响应,
In your uploadhandler.php library and change this line so that it will return the response,
public function post($print_response = true)
至public function post($print_response = false)
public function get($print_response = true)
至public function get($print_response = false)
protected function initialize()
至public function initialize()
已编辑:也对此进行了更改function __construct($options = null, $initialize = false, $error_messages = null)
EDITED: change this too function __construct($options = null, $initialize = false, $error_messages = null)
和
function initialize()
//
case 'POST':
return $this->post(); //Change this line like here
break;
////
case 'GET':
return $this->get(); //Change this line like here
break;
//
然后在调用库的函数中返回响应,
Then in the function where you calling the library get the response back,
require('UploadHandler.php');
$upload_handler = new UploadHandler();
$response = $upload_handler>initialize();
print_r($response); //Dump the response here and check
$custom_arr = //Save all your custom variables here (DB insert id, Text etc)
//Sample format of custom_arr
//$custom_arr['insert_id'] = $mysql_primary_key_id;
//$custom_arr['txt'] = $user_custom_text_field;
//
$response['custom_data'] = $custom_arr;
echo json_encode($response);
在前端,您可以使用fileuploaddone
回调获取数据并进行处理.
In your front end you can use the fileuploaddone
callback to get the data and play with it.
这篇关于jQuery File Upload,获取和编辑保存在数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!