jQuery文件上传,获取和编辑保存在DB中的数据

时间:2013-09-07 15:46:44

标签: php jquery jquery-ui jquery-file-upload

被修改

使用jQuery File Upload Documentation我可以使用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,但我找不到任何信息,但没有任何帮助我。

任何人都可以帮我这个或知道我在哪里可以找到这些信息吗?谢谢!

pic pic2

1 个答案:

答案 0 :(得分:2)

这将为您提供从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回调来获取数据并使用它。