要先清除文件状态缓存:
$year=date("Y",time());
if(!chdir("data/$year")) {
chdir("data");
mkdir($year);//如果不存在,直接建立文件夹
}
clearstatcache();//清除文件状态缓存
chdir("data/$year");
echo getcwd();
$year=date("Y",time());
if(!chdir("data/$year")) {
chdir("data");
mkdir($year);//如果不存在,直接建立文件夹
}
clearstatcache();//清除文件状态缓存
chdir("data/$year");
echo getcwd();
解决方案 »
- 怎么检测 $db->query("select ...")返回的结果集是否为空
- 帮忙看一下简单的代码.
- 有个.com的域名要卖
- 怎么修改购物车中商品的数量?
- 新手问题:什么是session
- 使用PHPLIB模板 如何生成HTML最快 最合适/
- 我用PHP在基于文件读写的基础上做的数据库,我把她叫做File Database。
- 试用期结束,老板一方面说很想留我,但迟迟不肯签合同,另外一方面在招人,我该怎么办?
- 代理服务器(Proxy Server)与SESSION or COOKIE ,很难的,请求帮助解决问题!!
- 大家好,最新免费主页空间开放
- phpmyadmin配置中扩展设置mbstring的问题
- 无人看守自动打印
Description
void clearstatcache ( void)
When you use stat(), lstat(), or any of the other functions listed in the affected functions list (below), PHP caches the information those functions return in order to provide faster performance. However, in certain cases, you may want to clear the cached information. For instance, if the same file is being checked multiple times within a single script, and that file is in danger of being removed or changed during that script's operation, you may elect to clear the status cache. In these cases, you can use the clearstatcache() function to clear the information that PHP caches about a file. 注: This function caches information about specific filenames, so you only need to call clearstatcache() if you are performing multiple operations on the same filename and require the information about that particular file to not be cached.
clearstatcache();
受影响的函数包括 stat(),lstat(),file_exists(),is_writable(),is_readable(),is_executable(),is_file(),is_dir(),is_link(),filectime(),fileatime(),filemtime(),fileinode(),filegroup(),fileowner(),filesize(),filetype() 和 fileperms()。
$year=date("Y",time());
if(! chdir("data/$year")) { //不要用这种方式试探目录是否存在,应用is_dir()或file_exists()检查。至少也要在chdir前面加个@。当然这不是主要问题
chdir("data"); //注意这里!你以在data目录下了
mkdir($year);
}
chdir("data/$year");//进入data/$year子目录,注意这里。你的data目录下有data/$year字目录吗?你刚才建的只是$year子目录
echo getcwd();//由于前面的chdir因找不到data/$year子目录而操作失败,自然目录就不会改变了刷新后就能正常显示,是因为目录已经存在,也就没有了chdir("data")的执行。而直接chdir("data/$year")当然也就可以了。
其实很简单,是我没搞清函数意义代码如下:$year=date("Y",time());
if(!is_dir("data/$year")) {
mkdir("data/$year");//如果不存在,直接建立文件夹
}
echo getcwd();