将数据从 Drupal 保存到本地系统文件
我创建了一个显示一些报告数据的 drupal 模块。我想包含一个选项,使查看页面的用户能够将数据保存为本地系统上的 txt 或 csv 文件,但我遇到了以下问题:
- 如何指定要保存到的本地目录。
- 如何实际将数据保存到目录中。
我已经阅读了表单的 drupal api 文档。有一种“文件”输入类型,允许用户浏览其系统并选择从中上传的位置。我还查看了 file_save_data() 函数,但似乎数据仅保存在 drupal 站点目录中。
任何帮助将不胜感激。
I have created a drupal module which displays some reporting data. I would like to include an option that enables a user viewing the page to save data as a txt or csv file on their local system, but I am running into the following problems:
- How to specify local directory to save to.
- How to actually save the data to the directory.
I've read through the drupal api documentation for forms. There is a 'file' input type that allows a user to browse their system and select a location to upload from. I've also looked at the file_save_data() function, but it seems that data is only saved within the drupal site directory.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能。用户的浏览器会将您的文件保存到浏览器的默认下载目录,或者提示用户选择一个位置。让网站选择文件的保存位置将是一个主要的安全漏洞——他们可以创建病毒的桌面快捷方式、添加启动项等。
You can't. The user's browser will save your files to either the browser's default downloads directory, or it'll prompt the user to pick a location. Letting a website pick where a file gets saved would be a major security hole - they could create desktop shortcuts to viruses, add startup items, etc.
这对我有用:
die() 需要进入那里,否则页面 html 将被附加到文件中。
This worked for me:
The die() needs to go in there, or else the page html will be appended to the file.