I am using Drupal 6, and would like to create content that can be exported. Specifically, I would like to be able to generate some random content string, and then 开发者_StackOverflow中文版be able to export it to the viewer as a text file. This would then pop up the usual dialog box from the browser about downloading content (etc.). I don't need to save the file on my server, because the content is constantly changing, and would prefer a solution that could avoid that.
I am a mildly proficient programmer, but not an expert on all of Drupal's functions. So the simpler the answer, the better.
Thanks
I found out the solution to my question. If you use php header() you will be able to accomplish this.
Here is a snippet of my code that I used to do it.
header("Content-Type: text/plain"); //the content type that I am exporting
header("Content-Disposition: Attachment; filename=myfilename.txt");
header("Pragma: no-cache"); //I don't want this to be cached because it is constantly changing
echo "My file contents";
exit(0);
There are many things to remember when doing this, much of which is documented in the link.
Hopefully this is useful to someone else
This sounds like a good job for Views and Views Bonus Pack and depending on your exact needs, maybe Views Bulk Operations (VBO).
From the Views Bonus page:
Views Bonus Pack 1 for Drupal 6
Export:
Allows fields to be exported to CSV, DOC, XML and themed text files.
精彩评论