is_file() - 判断给定文件名是否为一个正常的文件 - php 文件目录函数
is_file()
(PHP 4, PHP 5, PHP 7)
判断给定文件名是否为一个正常的文件
说明
is_file(string $filename): bool判断给定文件名是否为一个正常的文件。
参数
$filename文件的路径。
返回值
如果文件存在且为正常的文件则返回TRUE
,否则返回FALSE
。
Note:因为 PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB以上的文件,一些文件系统函数可能返回无法预期的结果。
范例
Example #1is_file()例子
以上例程会输出:
bool(true) bool(false)
错误/异常
失败时抛出E_WARNING
警告。
注释
Note:此函数的结果会被缓存。参见clearstatcache()以获得更多细节。
Tip自 PHP 5.0.0 起,此函数也用于某些URL 包装器。请参见支持的协议和封装协议以获得支持stat()系列函数功能的包装器列表。
参见
is_dir()
判断给定文件名是否是一个目录is_link()
判断给定文件名是否为一个符号连接
Note that is_file() returns false if the parent directory doesn't have +x set for you; this make sense, but other functions such as readdir() don't seem to have this limitation. The end result is that you can loop through a directory's files but is_file() will always fail.
if you're running apache as a service on a win32 machine, an you try to determinate if a file on an other pc in your network exists - ex.: is_file('//servername/share/dir1/dir2/file.txt') - you may return false when you're running the service as LocalSystem. To avoid this, you have to start the Apache-Service as a 'registered' domain user.
I tend to use alot of includes, and I found that the is_file is based on the script executed, not ran. if you request /foo.php and foo.php looks like this: and bar.php looks like this: Then PHP (on win32, php 5.x) would look for /foo/bar.txt and not /foobar/foo/bar.txt. you would have to rewrite the is_file statement for that, or change working directory. Noting this since I sat with the problem for some time, cheers, Toxik.
sometimes this function does not work because permission , you can use this function that check if the path has dot in last will return true . public function isFile($file) { $f = pathinfo($file, PATHINFO_EXTENSION); return (strlen($f) > 0) ? true : false; } isfile('http://www.ip4t.net/image.jpg'); you should replace a string between '' with your file path to check
regarding note from rehfeld dot us : In my experience the best( and easiest ) way to find the extension of a file is : or
It took me a day or so to figure out that is_file() actually looks for a valid $ existing path/file in string form. It is not performing a pattern-like test on the parameter given. Its testing to see if the given parameter leads to a specific existing 'name.ext' or other (non-directory) file type object.
### Symbolic links are resolved ### If you pass a symlink (unix symbolic link) as parameter, is_file will resolve the symlink and will give information about the refered file. For example: touch file ln -s file link echo '' | php -q will print "y". is_dir resolves symlinks too.
In PHP 4.1.0 under win32, this seems to print out a warning message if the file does not exist (using error_reporting = E_ALL & ~E_NOTICE).
here is a workaround for the file size limit. uses bash file testing operator, so it may be changed to test directories etc. (see http://tldp.org/LDP/abs/html/fto.html for possible test operators)
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)