You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							53 lines
						
					
					
						
							1.1 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							53 lines
						
					
					
						
							1.1 KiB
						
					
					
				| <?php | |
| 
 | |
| namespace app\controller; | |
| 
 | |
| use app\BaseController; | |
| use app\model\Article; | |
| 
 | |
| class ArticleController extends BaseController | |
| { | |
| 
 | |
|     public function sendArticle() | |
|     { | |
|         try { | |
|             $list = Article::field("*")->select()->toArray(); | |
|             foreach($list as $value) { | |
|                 $uuid = md5(time()); | |
|                 $html = $value['content']; | |
|                 $this->start(); | |
|                 $wordname = $uuid.'/article/'.$value['title'].".doc"; | |
|                 echo $html; | |
|                 $this->save($wordname); | |
|             } | |
|         } catch (\Exception $e) { | |
|             dd($e); | |
|         } | |
|     } | |
| 
 | |
|     function start() | |
|     { | |
|         ob_start(); | |
|         echo '<html xmlns:o="urn:schemas-microsoft-com:office:office" | |
| xmlns:w="urn:schemas-microsoft-com:office:word" | |
| xmlns="http://www.w3.org/TR/REC-html40">'; | |
|     } | |
| 
 | |
|     function save($path) | |
|     { | |
| 
 | |
|         echo "</html>"; | |
|         $data = ob_get_contents(); | |
|         ob_end_clean(); | |
| 
 | |
|         $this->wirtefile($path, $data); | |
|     } | |
| 
 | |
|     function wirtefile($fn, $data) | |
|     { | |
|         $fp = fopen($fn, "wb"); | |
|         fwrite($fp, $data); | |
|         fclose($fp); | |
|     } | |
| 
 | |
| }
 |