[pmwiki-users] How to export (:pagelist ...:) to a file e.g text/plain

Peter Bowers pbowers at pobox.com
Tue Jan 22 14:45:15 CST 2013


On Tue, Jan 22, 2013 at 1:40 PM, Sinan Kaan Yerli <
sinan at sinan.physics.metu.edu.tr> wrote:

>   * How could I redirect /this formatted/ output to a mimetype?
>           Do I have to introduce an ?action=export ...
>           If so how could I start the download of this data (i.e
>           download starts immediately without having a page to show).
>

A quick google of "automatic download dynamic php" resulted in this:

header('Content-Type: application/download');
    header('Content-Disposition: attachment; filename="example.txt"');
    header("Content-Length: " . filesize("example.txt"));

    $fp = fopen("example.txt", "r");
    fpassthru($fp);
    fclose($fp);

http://stackoverflow.com/questions/40943/how-to-automatically-start-a-download-in-php

The thing is you probably don't want a full MarkupToHTML() because you're
just looking for the text.  You might want to take a look at toolbox.php
and the RunMarkupRules() function there.  This would enable you to run the
"pagelist" rule to produce your dynamic download.

So that leaves (purely untested and probably loaded with bugs):

$HandleActions['export'] = 'HandleExport';
function HandleExport($pagename, $auth = 'read')
{
  $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
  if (!$page) Abort("?cannot read $pagename");
  $output = RunMarkupRules($pagename, array('pagelist'), $Text, $opt);
  header('Content-Type: application/download');
  header('Content-Disposition: attachment; filename="example.csv"');
  header("Content-Length: " . sizeof($output));
  echo $output; // I think this'll handle it.  Sometimes people talk about
the ob_* functions, but I usually try to avoid them.
}

-Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.pmichaud.com/pipermail/pmwiki-users/attachments/20130122/c2174ee3/attachment.html>


More information about the pmwiki-users mailing list