如何在WordPress后端强制下载文件?

时间:2012-06-17 17:37:31

标签: php wordpress wordpress-plugin wordpress-theming

大家好我有问题此代码必须在wordpress后端提供文件下载 但它给了我任何人可以帮助的jeson代码 这是我的代码

         $oprion_name_theme =  $this->theme->options['theme_options_field'];

         $shadyssa_options  =  $wpdb->get_results("SELECT option_name, option_value FROM $wpdb->options WHERE option_name like '%$oprion_name_theme%'");

         $resul = $shadyssa_options[0] ;

         $result = (array) $resul ;
         ob_start() ;
         $output =   json_encode($result) ;
         header("Content-type: application/octet-stream") ;
         header("Content-Disposition: attachment; filename='test.json'");
         header( 'Content-Length: ' . strlen( $output ) );   
         echo $output;

提前致谢

1 个答案:

答案 0 :(得分:0)

错字:

$result = (array) $resul ;
你要文件下载吗?但你输出为json

 header("Content-type: application/octet-stream") ;
 header("Content-Disposition: attachment; filename='test.json'");

你想要的是什么?