php目錄處理

1 php打開目錄opendir()函數打開目錄。

resoure opendir(string path)

成功返回目錄指針。不成功返回E_WARNING級別的錯誤信息。在opendir()前加“@”一直錯誤輸出。

關閉目錄:

closedir()函數;

void  closedir(resource handel)

2 目錄處理

瀏覽目錄scandir()

array scandir(string directory[,int sorting_order])

返回包含directory中的所有文件和目錄,sorting_order指定排序的順序。

bool mkdir(string pathname):新建一個指定的目錄

bool rmdir(string dirname):刪除置頂的目錄---------------------------------目錄必須爲空

string getcwd(void):取得當前工作的目錄。

bool chdir(string directory):更改當前的目錄爲directory

3 空間和目錄瀏覽

float disk_free_space(string directory):驗證權限後,查看目錄空間

 float disk_total_space(string directory)

 string readdir(resource handle)在使用opendir函數後返回目錄系啊一個文件名

 void rewinddir(resource handle):將置頂的目錄重新置頂到目錄的開頭。

4 遠程文件訪問

php支持URL格式的文件調用,只要在php.ini中配置一下即可。在php.ini文件中配置allow_url_fopen設置爲on,就可以了

fopen('http://127.0.0.1/index.php','rb')

 

 

 

5

bool rewind(resource handle)將文件handle文件的指針設置爲文件流開頭

int fseek(resource handle,int offset[,int whence])

handle:參數爲文件名稱

offset 參數爲指針的位置活相對whence參數的偏移量。可以是負數

whence:值可以是SEEK_SET(當前offset),SEEK_CUR(當前+offset),SEEK_END(文件末尾+offset),如果忽略默認是SEEK_SET

bool feof(resource handle)

如果文件指針到了文件末尾位置返回true否則返回false

 

int ftell(resource handle)//返回當前指針位置。

 

bool flock(int handle,int operation)//向一個文件寫入內容的時候,需要先鎖定該文件防止其他用戶同時也修改文件內容

其中operation爲:LOCK_SH(共享鎖)、LOCk_EX(獨佔所)、LOCK_UN(釋放鎖定)、LOCK_NB(防止使用該函數時候死鎖)

 

<?PHP
$filename ="test.txt";
readfile($filename);
echo "<br/><br/><br/><br/>";
$fd=fopen($filename,'w');
flock($fd,LOCK_EX);
fwrite($fd,"這是鎖定了之後添加的數據");
flock($fd,LOCK_UN);
fclose($fd);
readfile($filename);
?>

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章