$handle=fopen(“file”,”r”);
string fread (resource $handle ,int $length) ->从$handle开始至多多$length字节的内容,或则在这之前遇到eof结束。faied 返回FALSE
string fgets (resource $handle [,int $length]) ->一次读一行内容,$lenght参数决定最多可以读的字节
string fgetc (resource $handle ) ->读当前位置的一个字节。
|
//with fread; //with gets; //with getc ?> |
3写入文件
int fwrite ( resource handle, string string [, int length] )
is_writeable() //文件是否可写
4删除文件
unlink(“$filename”);
5截取文件
boot ftruncate(resource $handle ,int $size)
6远程访问文件
注意必须在php.ini中激活allow_url_fopen
$handle=fopen(“http://www.ankank.cn/file.txt”,”r“)
6返回文件指针的当前位置
ftell() ->返回文件指针当前位置
fseek() ->移动文件指针到指定的位置
fewink() ->移动文件指针到文件的开头
7生成临时文件
tmpfile() ->不具有任何参数,直接具有以写模式的临时文件
$ftmp_handle=tmpfile();
tempname() ->文件生成的临时文件不会被自动删除
8文件的锁定
bool flock ( int handle, int operation )
目录的操作
9遍历目录
|
|
10检索目录
array glob ( string pattern [, int flags] )
|
|
11建立目录
mkdir (“route”);
12删除目录和文件
rmdir(“route”)
unlink(“file”)
13复制和移动文件
copy(“a”,”b”);
rename(“a”,”b”);
move(“a”,”b”);
15文件的上传和下载
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<body>
<form method="POST" enctype="multipart/form-data" action="upfile.php">
<p>
<input type="file" name="upfile" size="20">
<input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2">
</p>
</form>
</body>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
<?php
$uploaddir = "d:\\";
$uploadfile =$uploaddir.$_FILES["upfile"]["name"] ;
//文件过滤
$error=array();
if($_FILES["upfile"]["size"]>40000)
{
$error[]="文件太大" ;
}
if($_FILES["upfile"]["type"]!= "text/plain")
{
$error[]="文件类型错误";
}
if(count($error))
{
//发现错误
print_r($error);
echo "<hr>";
echo join("<br>",$error);
}
else
{
if ( move_uploaded_file($_FILES["upfile"]["tmp_name"],$uploadfile))
{
print "文件上传成功";
}
else
{
print "文件上传失败" ;
}
echo $_FILES["upfile"]["size"];
}
?>
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
转载自:http://blog.chinaunix.net/u1/46911/showart_393631.html
这个星期主要在看PHP文件处理的方面的知识,这篇php文件处理感觉不错就转载了