[wp-hackers] exporting a file in wp admin

Dion Hulse (dd32) wordpress at dd32.id.au
Sun May 23 13:07:29 UTC 2010


Chances are, your code is running way too late, Probably after the header  
and menu have been outputted (Its about this time that the plugin page  
gets included)

Use admin-post.php and direct the download through that, no WP UI is  
outputted when called through there, and it'll be limited to the currently  
logged in user.

(Please do put a nonce on it though)

Dion


On Sun, 23 May 2010 22:30:30 +1000, Steve Taylor <steve at sltaylor.co.uk>  
wrote:

> I'm trying to send a spreadsheet created with PHP on a WP admin page
> to the browser for download. The relevant code I've got is:
>
> header( "Content-Type: application/vnd.ms-excel" );
> header( 'Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT' );
> header( "Content-disposition: attachment; filename=download-logs.xls" );
> header( 'Pragma: no-cache' );
> echo $spreadsheet;
> exit;
>
> I gather there's a few different options for the header settings, but
> I think the problem I've got is more basic than that. What I'm seeing
> is just the normal WP admin page, with the spreadsheet data dumped as
> a string. These are the response headers (via Web Developer in
> Firefox):
>
> Date: Sun, 23 May 2010 12:28:56 GMT
> Server: Apache/2.2.3 (CentOS)
> X-Powered-By: PHP/5.1.6
> Expires: Wed, 11 Jan 1984 05:00:00 GMT
> Last-Modified: Sun, 23 May 2010 12:28:57 GMT
> Cache-Control: no-cache, must-revalidate, max-age=0
> Pragma: no-cache
> Keep-Alive: timeout=15, max=500
> Connection: Keep-Alive
> Transfer-Encoding: chunked
> Content-Type: text/html; charset=UTF-8
> 200 OK
>
> I suspect I'm missing the trick of clearing the header settings
> already specified by WP itself. I tried ob_clean() at the start, but
> then I just see a blank WP admin page.
>
> Any help appreciated!
>
> Steve Taylor
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


-- 
Dion Hulse / dd32
Contact:
  e: contact at dd32.id.au
  Web: http://dd32.id.au/


More information about the wp-hackers mailing list