php读取本地文件操作函数
2013-09-05 18:33
344 查看
在php中读取本地文件我们最常用的就是fopen与fread函数配置使用即可了,还有一些其它的像php file_get_contents可以读本地文件也可以读远程文件了,下面我们来一一介绍一下。
fopen() 函数
直接打开文件
例
代码如下
$file = "111.txt";
$fp = fopen($file,"r");
if ($fp){
while(!feof($fp)){
//第二个参数为读取的长度
$data = fread($fp, 1000);
}
fclose($fp);
}
echo $data;
?>
file_get_contents() 函数把整个文件读入一个字符串中
例子
代码如下
echo file_get_contents("test.txt");
?>
输出:
This is a test file with test text.
php读取本地文件夹文件
代码如下
$dir = opendir('/movie');
while(($file = readdir($dir))!=false){
if ($file!="." && $file!="..") {
$ns = explode('.', $file);
echo $ns[0];
}
}
closedir($dir);
?>
fopen() 函数
直接打开文件
例
代码如下
$file = "111.txt";
$fp = fopen($file,"r");
if ($fp){
while(!feof($fp)){
//第二个参数为读取的长度
$data = fread($fp, 1000);
}
fclose($fp);
}
echo $data;
?>
file_get_contents() 函数把整个文件读入一个字符串中
例子
代码如下
echo file_get_contents("test.txt");
?>
输出:
This is a test file with test text.
php读取本地文件夹文件
代码如下
$dir = opendir('/movie');
while(($file = readdir($dir))!=false){
if ($file!="." && $file!="..") {
$ns = explode('.', $file);
echo $ns[0];
}
}
closedir($dir);
?>
相关文章推荐
- php读取本地文件常用函数
- php读取本地文件常用函数
- PHP文件操作,多行句子的读取,file()函数,file_get_contents()函数,file_put_contents()函数,is_file,统计网站pv (访问量),文件的复制 copy
- php读取本地文件常用函数(fopen与file_get_contents)
- php读取本地文件常用函数(fopen与file_get_contents)
- php读取文件操作函数
- PHP常用文件操作函数
- PHP部分文件操作函数
- PHP文件系统函数详细使用与操作(一)
- php中配置文件操作 如config.php文件的读取修改等操作
- 用文件操作函数读取图文档信息
- PHP获取和操作配置文件php.ini的几个函数
- php 常用函数总结(数组,字符串,时间,文件操作)
- PHP读取CSV文件把数据插入到数据库,本地没有问题,阿里云测试服务器不行
- 读取本地文件到读出p.node涉及的函数
- PHP文件操作函数
- php基础知识之文件操作函数以及计数器
- PHP读取,写入MYSQL数据库文件操作
- PHP学习之[第07讲]PHP5.4 文件操作函数 之 图片计数器的实例
- php对csv文件的读取,写入,输出下载操作