批處理和檔案系統: php的檔案系統處理

來源:互聯網
上載者:User

開啟檔案,處理檔案,關閉檔案
1開啟、關閉檔案
is_file($filename)
resource fopen($filename,$mode[,use_include_path)
$filename:可以是絕對路徑,也可以是相對路徑
$mode是開啟的模式,讀寫。。。等
第三個是是否在伺服器的這個路徑下開啟檔案。
關閉檔案 
bool fclose(resource handle);
sample:
$f = fopen("a.txt","rb");
fclose($f)
2.讀寫檔案
int readfile($filename)讀取整個檔案寫入到輸出緩衝,不需要開啟檔案,不需要echo,print。
array file($filename) 讀取整個檔案的內容,按行儲存到數組。
file_get_contents($filename,)  將檔案讀取到一個字串中
讀取一行:
fgets($resource)一次讀取一行.如果遇到分行符號,EOF,讀取到了指定的長度後結束。
fgetss($resource,$length)上面函數的變體,過濾掉html,php標記
讀取一個字元
fgetc($resource)
判斷是否到檔案結束地方
while(!feof($resource))
fread($resource,length) 讀取指定長度的資料。
向檔案寫入資料
fwrite($resource,$string,length)
file_put_contents($filename,$string)
其他檔案操作
bool copy($path1,$path2)
bool rename($filename1,$filename2)
bool unlink($filename) 刪除檔案
array pathinfo($filename)
realpath($filename) 絕對路徑

目錄函式,目錄操作
如果開啟一個不存在的檔案,就會建立新檔案,如果開啟一個不存在的額目錄就會報錯。
開啟,關閉目錄
resource opendir($path)
@opendir($path)抑制錯誤輸出
closedir($resource) 關閉目錄。
is_dir()先判斷$path再開啟。
瀏覽目錄scandir
array scandir($path)
目錄操作
bool mkdir($path)建立一個指定目錄
bool rmdir($dirname)刪除一個目錄,目錄必須使空的
string getcwd()獲得當前工作目錄
bool chdir()改變目前的目錄為。
進階應用程式
fopen("http://127.0.0.1/tm/sl/index.php")開啟遠程檔案。。。php配置 allow_url_fopen on
檔案指標:
bool rewind($resource) 把檔案指標指向到開始處
fseek($resource,$offset,$model)  定位檔案指標
bool feof($resource) 判斷是否在檔案尾  file  end of  file
ftell($resource)報出指標的位置
鎖定檔案flock($resource,$model)
檔案上傳
phpini設定,
1是否允許上傳檔案 file_uploads  on off
2upload_tmp_dir 上傳檔案的暫時目錄
3:upload_max_filesize伺服器允許上傳的最大值MB為單位
預定義變數#$_FILES
數組第一級鍵名為name,第二級鍵名name,size,tmp_name(move_upload_file($sourcefile,$目的檔案)),type,error(0表示成功)
多個檔案上傳,name="name[]"
本文連結http://www.cxybl.com/html/wlbc/Php/20130608/38519.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.