老师 为什么你的能删掉?而不是死循环?
<?php
class File{
private $_dir;
const EXT = '.txt';
public function __construct(){
$this->_dir = dirname(__FILE__).'/files/';
}
public function cacheData($key, $value='', $path=''){
$filename = $this->_dir.$path.$key.self::EXT;
print_r($filename);
if($value !== ''){
if(is_null($value)){
if(file_exists($filename)){
var_dump(unlink($filename));
}else{
echo 1111;
}
}else{
echo 2222222;
}
//$dir = dirname($filename);
//if(!is_dir($dir)){
// mkdir($dir,0777);
//}
return file_put_contents($filename, json_encode($value));//返回字节数
}
// if(!is_file($filename)){
// return false;
// }else{
// return json_decode(file_get_contents($filename),true);
// }
}
}第29行的return file_put_content 在你unlink之后不是又会重新创建一个新的文件吗?为什么你的不会???