php is_writable判断文件是否可写实例代码
网络编程 2021-07-05 08:23www.168986.cn编程入门
这篇文章主要介绍了php is_writable判断文件是否可写实例代码的相关资料,需要的朋友可以参考下
php is_writable函数介绍
is_writable — 判断给定的文件名是否可写,该函数的结果会被缓存。请使用 clearstatcache() 来清除缓存。
语法:
bool is_writable ( string $filename )
如果文件存在并且可写则返回 TRUE 。filename 参数可以是一个允许进行是否可写检查的目录名。
记住 PHP 也许只能以运行 webserver 的用户名(通常为 'nobody')来访问文件。不计入安全模式的限制。
参数:
filename 要检查的文件名称。
返回值:
如果文件 filename 存在并且可写则返回 TRUE 。
php is_writable实例
使用is_writable函数判断给定的文件是否可读:
<?php $filename = "test.text"; if (is_readable($filename)) { echo "文件 $filename 可读"; } else { echo "文件 $filename 不可读"; } ?>
其实我们也可以自己写一个函数来判断文件是否可读,而不需要使用php内置函数is_writable,以下函数可用于替换php内置的is_writable函数,大家可以参考一下:
//可用于替换php内置的is_writable函数 function isWritable($filename){ if(preg_match('/\/$/',$filename)){ $tmp_file=sprintf('%s%s.tmp',$filename,uniqid(mt_rand())); return isWritable($tmp_file); } if(file_exists($filename)){ //文件已经存在的话,使用读写方式打开 $fp=@fopen($filename,'r+'); if($fp){ fclose($fp); return true; } else{ return false; } } else{ $fp=@fopen($filename,'w'); if($fp){ fclose($fp); unlink($filename); return true; } else{ return false; } } }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
上一篇:用php和jQuery来实现“顶”和“踩”的投票功能
下一篇:基于PHP制作验证码
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程