php中的filesystem檔案系統函數使用樣本

來源:互聯網
上載者:User

 這篇文章主要介紹了php中的filesystem檔案系統函數使用樣本,需要的朋友可以參考下

basename — 返迴路徑中的檔案名稱部分dirname — 返迴路徑中的目錄部分  代碼如下:string basename ( string $path [, string $suffix ] )string dirname ( string $path )  樣本:  代碼如下:<?php$path = "/home/httpd/phpha.com/index.php";echo basename($path);echo basename($path, '.php');echo basename($path, '.xxx');echo dirname($path);?>  代碼如下://結果:index.phpindexindex.php/home/httpd/phpha.com  說明:如果檔案名稱是以正確的suffix結束的,那這一部分也會被去掉。 chgrp — 改變檔案所屬的組chown — 改變檔案的所有者chmod — 改變檔案模式 代碼如下:bool chmod ( string $filename , int $mode )  樣本:  代碼如下:<?phpchmod('/home/phpha.txt', 0755);?>copy — 拷貝檔案 if(copy('index.php', 'index.php.bak')){ echo 'copy success';}?>//在目前的目錄下生存了index.php.bak檔案   delete — 參見 unlink 或 unsetunlink — 刪除檔案代碼如下:<?phpif(unlink('index.php.bak')){ echo 'unlink success';}?>//刪除了index.php.bak  disk_free_space — 返回目錄中的可用空間disk_total_space — 返回一個目錄的磁碟總大小diskfreespace — disk_free_space 的別名  代碼如下:<?php//在 Windows 下:echo disk_free_space("C:"), '<br />';echo disk_total_space("C:");?>代碼如下://結果:返回的是位元組數1743341977632218386432  fopen — 開啟檔案或者 URLfgets — 從檔案指標中讀取一行feof — 測試檔案指標是否到了檔案結束的位置fread — 讀取檔案(可安全用於二進位檔案)fwrite — 寫入檔案(可安全用於二進位檔案)fclose — 關閉一個已開啟的檔案指標  代碼如下:<?php$fp = fopen('hello.txt', 'r'); //開啟一個檔案$n = 1;while(!feof($fp)){ echo $n, ' - ', fgets($fp), '<br />'; //讀取一行並輸出 $n++;}fclose($fp); //關閉檔案?>  代碼如下://輸出:1 - Welcome to my blog:2 - http://www.jb51.net  fgetc — 從檔案指標中讀取字元fgetcsv — 從檔案指標中讀入一行並解析 CSV 欄位fgetss — 從檔案指標中讀取一行並過濾掉 HTML 標籤fputcsv — 將行格式化為 CSV 並寫入檔案指標fputs — fwrite 的別名 代碼如下:<?php$fp = fopen('hello.txt', 'r');while(false !== ($char = fgetc($fp))){    echo $char, '-';}?>   代碼如下://輸出:W-e-l-c-o-m-e- -t-o- -m-y- -b-l-o-g-:- - -h-t-t-p-:-/-/-b-l-o-g-.-p-h-p-h-a-.-c-o-m-  file_exists — 檢查檔案或目錄是否存在  複製代碼 代碼如下:<?phpif(file_exists('hello.txt')){ echo 'hello.txt exists';}else{ echo 'hello.txt not exists';}?> [/code]//輸出:hello.txt exists[/code] file_get_contents — 將整個檔案讀入一個字串file_put_contents — 將一個字串寫入檔案file — 把整個檔案讀入一個數組中 代碼如下:<?phpif($content = file_get_contents('hello.txt')){ file_put_contents('hello.txt.bak', $content);}?>//相當於copy了一份hello.txt<?phpif($content = file('hello.txt')){ print_r($content);}?>//數組形式,每一行是一個數群組成員Array(    [0] => Welcome to my blog:    [1] => http://www.jb51.net)  fileatime — 取得檔案的上次訪問時間filectime — 取得檔案的 inode 修改時間filegroup — 取得檔案的組fileinode — 取得檔案的 inodefilemtime — 取得檔案修改時間fileowner — 取得檔案的所有者fileperms — 取得檔案的許可權filesize — 取得檔案大小filetype — 取得檔案類型  代碼如下:<?phpecho fileatime('hello.txt');echo filectime('hello.txt');echo filegroup('hello.txt');echo filemtime('hello.txt');echo fileowner('hello.txt');echo substr(sprintf('%o', fileperms('hello.txt')), -4);echo filesize('hello.txt');echo filetype('hello.txt');?>   複製代碼 代碼如下://輸出:13533290031353329003013533300020066642file  flock — 輕便的諮詢檔案鎖定fnmatch — 用模式比對檔案名稱fflush — 將緩衝內容輸出到檔案fpassthru — 輸出檔案指標處的所有剩餘資料fscanf — 從檔案中格式化輸入fseek — 在檔案指標中定位fstat — 通過已開啟的檔案指標取得檔案資訊ftell — 返迴文件指標讀/寫的位置ftruncate — 將檔案截斷到給定的長度glob — 尋找與模式比對的檔案路徑 is_dir — 判斷給定檔案名稱是否是一個目錄is_executable — 判斷給定檔案名稱是否可執行is_file — 判斷給定檔案名稱是否為一個正常的檔案is_link — 判斷給定檔案名稱是否為一個符號串連is_readable — 判斷給定檔案名稱是否可讀is_uploaded_file — 判斷檔案是否是通過 HTTP POST 上傳的is_writable — 判斷給定的檔案名稱是否可寫is_writeable — is_writable 的別名說明:以上函數都是用來判斷檔案或目錄是否符合對應的條件,返回TRUE或FALSE。 lchgrp — Changes group ownership of symlinklchown — Changes user ownership of symlinklink — 建立一個硬串連linkinfo — 擷取一個串連的資訊lstat — 給出一個檔案或符號串連的資訊mkdir — 建立目錄move_uploaded_file — 將上傳的檔案移動到新位置parse_ini_file — 解析一個設定檔pathinfo — 返迴文件路徑的資訊pclose — 關閉進程檔案指標popen — 開啟進程檔案指標readfile — 輸出一個檔案readlink — 返回符號串連指向的目標realpath — 返回正常化的絕對路徑名rename — 重新命名一個檔案或目錄rewind — 倒迴文件指標的位置rmdir — 刪除目錄set_file_buffer — stream_set_write_buffer 的別名stat — 給出檔案的資訊symlink — 建立符號串連tempnam — 建立一個具有唯一檔案名的檔案tmpfile — 建立一個臨時檔案touch — 設定檔案的訪問和修改時間umask — 改變當前的 umaskclearstatcache — 清除檔案狀態緩衝 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.