PHP文件操作函数

$file=file_get_contents('url');直接将文件读入字符串中

readfile('url')直接将文件显示在屏幕上,是一种保护文件和带宽防盗链的手段。

fopen('url',params)返回文件句柄。

处理小文件:$file_contents=fread($fp,filesize($locate));

处理较大文件:while(!feof($fp)){$chunk=fgets($fp) ; echo $chunk } fclose($fp);

//写入文件

fwrite($fp,$line);

file_exists()

is_file()

is_readable()

is_writable()

filemtime()

fileatime()

filesize()

检查目录

opendir() readdir() closedir()类似于fopen fread fclose

如何在线显示php源码

highlight_file()

highlight_string()

如何在文件中存储配置信息

config.ini

parse_ini_file()解析ini相同格式的文件

parse_ini_file('config.ini',true);返回一个数组。

一般来将不要把配置文件放在web根目录下,应该放在根目录之外,从而使黑客和google无法访问。若必须放,则一定要用htaccess文件中包含一条文件指令。或者加密。

如何访问远程服务器上的文件。fopen('http://url','r');

php中利用ftp

$fp=ftp_connect($ftpserver,21,30)

if(!ftp_login($fp,'username','something'));

if(!ftp_chdir($fp,$targetDir))

current directory  ftp_pwd($fp);

$files=file_nlist($fp,'/');array

PEAR::NET_FTP

在PHP5中可以使用SPL功能,

DirectoryIterator类

原文地址:https://www.cnblogs.com/phplover/p/3095491.html