當前位置:首頁 » 文件管理 » thinkphp刪除緩存文件

thinkphp刪除緩存文件

發布時間: 2024-01-09 10:46:00

① thinkphp創建完項目後可以刪掉ThinkPHP文件夾

ThinkPHP文件夾包含ThinkPHP框架的核心文件,刪掉的話,整個就廢了。
當然你可以對文件夾進行更名,只要做相應設置即可,但版權信息不允許刪除。

② thinkphp 如何實現清除緩存

ThinkPHP後台執行的代碼:
//獲取要清楚的目錄和目錄所在的絕對路徑
public function cache(){
////前台用ajax get方式進行提交的,這里是先判斷一下
if($_POST['type']){
//得到傳遞過來的值
$type=$_POST['type'];
//將傳遞過來的值進行切割,我是用「-」進行切割的
$name=explode('-', $type);
//得到切割的條數,便於下面循環
$count=count($name);
//循環調用上面的方法
for ($i=0;$i<$count;$i++){
//得到文件的絕對路徑
$abs_dir=dirname(dirname(dirname(dirname(__FILE__))));
//組合路徑
$pa=$abs_dir.'indexRuntime';
$runtime=$abs_dir.'indexRuntime~runtime.php';
if(file_exists($runtime))//判斷 文件是否存在
{
unlink($runtime);//進行文件刪除
}
//調用刪除文件夾下所有文件的方法
$this->rmFile($pa,$name[$i]);
}
//給出提示信息
$this->ajaxReturn(1,'清除成功',1);
}else{
$this->display();
}
}
public function rmFile($path,$fileName){//刪除執行的方法
//去除空格
$path = preg_replace('/(/){2,}|{}{1,}/','/',$path);
//得到完整目錄
$path.= $fileName;
//判斷此文件是否為一個文件目錄
if(is_dir($path)){
//打開文件
if ($dh = opendir($path)){
//遍歷文件目錄名稱
while (($file = readdir($dh)) != false){
//逐一進行刪除
unlink($path.''.$file);
}
//關閉文件
closedir($dh);
}
}
}
前台頁面部分代碼如下:
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.js"></script>
<script type="test/javascript">
$(function(){
$('#button').click(function(){
if(confirm("確認要清除緩存?")){
var $type=$('#type').val();
var $mess=$('#mess');
$.post('__URL__/clear',{type:$type},function(data){
alert("緩存清理成功");
});
}else{
return false;
}
});
});
</script>

③ thinkphp5模型如何使用redis操作資料庫CURD操作

模型中添加如下代碼,可實現更新或插入前刪除緩存:
protected static function init()
{
TurnGiftSetting::beforeInsert(function ($model) {
$redis = new Redis(config('redis'));
$redis->rm(self::$redisKey);
});
TurnGiftSetting::beforeUpdate(function ($model) {
$redis = new Redis(config('redis'));
$redis->rm(self::$redisKey);
});

TurnGiftSetting::beforeDelete(function ($model) {
$redis = new Redis(config('redis'));
$redis->rm(self::$redisKey);
});
TurnGiftSetting::beforeWrite(function ($model) {
$redis = new Redis(config('redis'));
$redis->rm(self::$redisKey);
});
}

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:637
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:366
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:82
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:308
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:789
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:339
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:210
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:810
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:364
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:590