PHP基础 文件流

来源:互联网 发布:国家电网软件注册流程 编辑:程序博客网 时间:2024/04/29 02:35
?php #basename(path[,suffix]) 返回路径的文件名部分 $path="/thinkphp/Examples/readme.txt"; echo "p".basename($path)."/p"; #dirname()获得路径目录 echo "p".dirname($path)."/p"; #pathinfo()由目录,基本名和扩展名组成 $pathinfo=pathinfo($path); echo "p目录名:".$pathinfo['dirname'].";基本名:".$pathinfo['basename'].";扩展名:".$pathinfo['extension']."/p"; #realpath(path) 绝对路径 $path="thinkphp/Examples/readme.txt"; $url=realpath($path); echo "pa href='".$url."'".basename($path)."/a/p"; #filesize()确定文件大小 $bytes=filesize($path); echo "p这个文件大小为:".round($bytes/1024,2)."KB/p"; #disk_free_space(dir)计算磁盘可用空间 #disk_total_space(dir)计算磁盘总空间 $drive="F:"; echo "p$drive共".round(disk_total_space($drive)/1048576,2)."MB;".round(disk_free_space($drive)/1048576,2)."MB空间可用/p"; #最后访问和修改时间 fileatime() // echo "p".date("m-d-y g:i:sa",flieatime($path))."/p"; 最后访问 // echo "p".date("m-d-y g:i:sa",fliectime($path))."/p"; 最后改变 // echo "p".date("m-d-y g:i:sa",fliemtime($path))."/p"; 最后修改 #fopen(resource,mode,[,use_include_path,zcontext] 打开文件 $fh=fopen("demo.html","w",1); $fh=fopen("http://google.com","r"); //fclose($fh); #file()将文件读取到数组中,换行作为分隔 $demo=file("demo.txt"); foreach($demo as $d){ list($title,$content)=explode(" ",$d); echo "ph1$title/h1$content/p"; } #file_get_contents()将文件中的内容读到字符串 $myfile=file_get_contents("demo.txt"); echo "p$myfile/p"; #读取csv到数组 fgetcsv() $fh=fopen("demo.csv","r"); while(list($month,$isbn)=fgetcsv($fh,1024,",")){ printf("p%s(%s)/p",$month,$isbn); } #fgets(resource[,length]) 返回length个字符 #fgetss()从输入中剔除 // $tags="aimgtableulli"; // $fh=fopen("demo.html","rt"); // while(!feof($fh)){ // $article.=fgetss($fh,1024,$tags); // } // fclose($fh); // $fh=fopen("demo.html","wt"); //fwrite($fh,$article); // fclose($fh); #string fgetc(resource) 一次读取一个字符 #string fread(resource,length) 读取length个字符,不考虑换行符 $file="demo.txt"; $fh=fopen($file,"rt"); $userdata=fread($fh,filesize($file)); fclose($fh); #readfile(filename,use_include_path) 读取整个文件 #fscanf(resource,format[,var1]) 预定格式读取 #fwrite(resource,string,[,length]) 将字符串输出到指定资源 #int fseek(resource,offset,[whence])将指针移到给定的偏移量指定位置 #ftell()获得当前位置偏移量 #rewind()将文件指针移回资源头部 #opendir(path)打开目录 #closedir()关闭目录 #readir()解析目录 $dh=opendir("./thinkphp"); while($file=readdir($dh)) { echo "$filebr"; } closedir($dh); #scandir()将目录读入数组 print_r(scandir("./thinkphp")); #rmdir(dirname) 删除目录 #rename(oldname,newname)重命名文件 #exec(command[,output[,return_var]])后台连续执行操作系统级应用程序 //...剩下参考API ?


原创粉丝点击