Home  >  Article  >  php教程  >  获取文件的相关信息

获取文件的相关信息

PHP中文网
PHP中文网Original
2016-05-25 16:58:48913browse

获取文件的相关信息


// 获取文件信息
function get_file_info($file)
{
	if(is_file($file) == false)
	{
		return false;
	}
	
	$ret['path'] = realpath($file); // 路径
	
	$tmp = explode('.', $file);
	
	rsort($tmp); // 翻转数组
	
	$ret['type'] = $tmp[0]; // 文件类型
	
	array_shift($tmp); // 从数组中摘除首元素
	
	rsort($tmp);
	
	$ret['filename'] = implode('.', $tmp); // 文件名
	
	$ret['createtime'] = date('Y-m-d H:i:s', filectime($file)); // 创建时间
	
	$ret['updatetime'] = date('Y-m-d H:i:s', filemtime($file)); // 最后一次更改时间
	
	$ret['size'] = filesize($file).'(Byte)';
	
	// 按行读取文件
	$fp = fopen($file, 'r');
	$i = 1;
	while(! feof($fp))
	{
		$lines[$i] = fgets($fp);
		$i++;
	}
	fclose($fp);
	
	$ret['rows'] = count($lines); // 总行数
	$ret['lines'] = $lines; // 每行的内容
	
	print_r($ret);
	
}

                   

 以上就是获取文件,相关信息的内容,更多相关内容请关注PHP中文网(m.sbmmt.com)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn