jQuery文件上传,获取和编辑保存在DB中的数据
编辑
使用jQuery文件上载文档,我可以使用MySQL DB中的图片保存数据(参见图1 + 2)
现在我陷入困境的是如何检索数据。 上传之后我想用DB中的数据显示图片,但我没有找到如何做到这一点。
如果有人知道如何编辑json附加数据库数据或者我怎么能var_dump它只是为了让我朝着正确的方向推进,这将是非常棒的! 我无法找到json的创建位置。 json现在看起来像这样:
{"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解释的那样)并改变了以下内容
require('UploadHandler.php'); $upload_handler = new UploadHandler(); $response_enc = $this->upload_handler->initialize();
但是我得到的错误是“JSON.parse:JSON数据后出现意外的非空白字符”,而且我为此找到了googeld,但我找不到任何信息,但没有任何帮助我。
任何人都可以帮我这个或知道我在哪里可以找到信息? 谢谢!
这将为您提供从uploadhandler库编辑json响应的基本思路,
编辑:
在你的uploadhandler.php库中更改这一行,以便它返回响应,
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)
并在
function initialize() // case 'POST': return $this->post(); //Change this line like here break; //// case 'GET': return $this->get(); //Change this line like here break; //
然后在您调用库的函数中获取响应,
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
回调来获取数据并使用它。