gpt4 book ai didi

php - ExtJS 网格表单与 MySQL 中的文档

转载 作者:行者123 更新时间:2023-11-29 14:50:38 25 4
gpt4 key购买 nike

我有一个网格,其中的数据来自数据库。网格的每一行都包含这些字段:文档名称、所有者、版本等。文档的内容位于 blob 中。

我希望当用户双击一行时下载文档的内容。最好的方法是弹出一个要求确认的窗口。网格必须保留在屏幕上。

我能够使用 ajax 请求读取文档的内容并将结果放入变量中。

                            Ext.Ajax.request({
url: '../controleurs/c_get_doc_content.php',
method: 'POST',
params: { dep: r.data.nom_document },
success: function(response, opts) {console.log(response);console.log(opts)},
requestcomplete: function (conn, response, options) {},
failure: function() {console.log('failure');},
headers: { 'my-header': 'foo' },

如何将文档内容保存到用户 PC 上的文件中?

最佳答案

最好的解决方案是服务器端。您只需传递一个 ID,而不是将 blob 传递给 JS。然后,当用户选择下载文件时,您调用服务器,它会返回一个可以下载的文档。

您只需将该内容作为附件进行流式传输,而不是通过 AJAX 请求发送

在 PHP 中,您可以使用以下代码来确保下载文件并显示“另存为”对话框。

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}

关于php - ExtJS 网格表单与 MySQL 中的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5809167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com