PHP基礎 檔案流

2022-04-23 09:51:48 字數 2708 閱讀 5428

<?php 

#basename(path[,suffix]) 返回路徑的檔名部分

$path="/thinkphp/examples/readme.txt";

echo "".basename($path)."

"; #dirname()獲得路徑目錄

echo "".dirname($path)."

"; #pathinfo()由目錄,基本名和副檔名組成

$pathinfo=pathinfo($path);

echo "目錄名:".$pathinfo['dirname'].";基本名:".$pathinfo['basename'].";副檔名:".$pathinfo['extension']."

"; #realpath(path) 絕對路徑

$path="thinkphp/examples/readme.txt";

$url=realpath($path);

echo "".basename($path)."

"; #filesize()確定檔案大小

$bytes=filesize($path);

echo "這個檔案大小為:".round($bytes/1024,2)."kb

";

#disk_free_space(dir)計算磁碟可用空間

#disk_total_space(dir)計算磁碟總空間

$drive="f:";

echo "$drive共".round(disk_total_space($drive)/1048576,2)."mb;".round(disk_free_space($drive)/1048576,2)."mb空間可用

"; #最後訪問和修改時間 fileatime()

// echo "".date("m-d-y g:i:sa",flieatime($path))."

"; 最後訪問

// echo "".date("m-d-y g:i:sa",fliectime($path))."

"; 最後改變

// echo "".date("m-d-y g:i:sa",fliemtime($path))."

"; 最後修改

#fopen(resource,mode,[,use_include_path,zcontext] 開啟檔案

$fh=fopen("demo.html","w",1);

$fh=fopen("","r");

//fclose($fh);

#file()將檔案讀取到陣列中,換行作為分隔

$demo=file("demo.txt");

foreach($demo as $d)

#file_get_contents()將檔案中的內容讀到字串

$myfile=file_get_contents("demo.txt");

echo "$myfile

"; #讀取csv到陣列 fgetcsv()

$fh=fopen("demo.csv","r");

while(list($month,$isbn)=fgetcsv($fh,1024,","))

#fgets(resource[,length]) 返回length個字元

#fgetss()從輸入中剔除

// $tags="

"; // $fh=fopen("demo.html","rt");

// while(!feof($fh))

// 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))

closedir($dh);

#scandir()將目錄讀入陣列

print_r(scandir("./thinkphp"));

#rmdir(dirname) 刪除目錄

#rename(oldname,newname)重新命名檔案

#exec(command[,output[,return_var]])後台連續執行作業系統級應用程式

//...剩下參考api

?>

php流以及檔案函式

1.int file put contents string filename,string data int flags,resource context 函式功能 將乙個字串寫入檔案。filename 要被寫入的資料檔名。data 要寫入的資料。型別可以是string,array或者是strea...

C 基礎 IO檔案流

const string filepath 直接構造且以讀取模式開啟檔案 ifstream if1 filepath filedata.txt string line vectorstrvec if if1 預設構造,呼叫open函式以讀取模式開啟檔案,且用is open判斷開啟是否成功 ifstr...

php 傳送與接收流檔案

php 傳送與接收流檔案 sendstreamfile.php 把檔案以流的形式傳送 receivestreamfile.php 接收流檔案並儲存到本地 sendstreamfile.php php 傳送流檔案 param string url 接收的路徑 param string file 要傳送...