1 <div class="panel panel-default"> 2 <div class="panel-body"> 3 <div> 4 <a href="javascript:void(0);" id="deleteCacheLink" class="btn btn-success btn-sm">清除文件缓存</a> 5 </div> 6 <div id="deleteCacheMessage"></div> 7 </div> 8 </div> 12 <script> 13 14 $(function(){ 15 $('#deleteCacheLink').click(function(){ 16 if(confirm("是否清除文件缓存?")) { 17 $('#deleteCacheMessage').html('正在清除文件缓存...'); 18 $.get("<?=Url::to(['delfilecache']);?>", function(data){ 19 if(data == 1) { 20 $('#deleteCacheMessage').html('成功清除文件缓存!'); 21 } else { 22 $('#deleteCacheMessage').html('清除文件缓存失败!'); 23 } 24 }); 25 } 26 }); 27 }); 28 </script>
1 //yii2.0目录删除,删除成功输出1 2 3 public function actionDelfilecache() 4 { 5 $cachePath = Yii::getAlias('@app/runtime/cache'); 6 $fileArray = scandir($cachePath); 7 foreach($fileArray as $fileName) { 8 if($fileName != "." && $fileName != ".."){ 9 if(is_dir($cachePath . '/' . $fileName)) { 10 //yii2.0自带的文件删除 11 FileHelper::removeDirectory($cachePath . '/' . $fileName); 12 } else { 13 unlink($cachePath . '/' . $fileName); 14 } 15 } 16 } 17 echo 1; 18 }