国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Inhaltsverzeichnis
1. H?ufig verwendete Dateifunktionsbibliothek" >1. H?ufig verwendete Dateifunktionsbibliothek
1. basename(); – Gibt den Dateinamenteil des Pfads zurück. " > 1. basename(); – Gibt den Dateinamenteil des Pfads zurück.
2. dirname(); – Gibt den Verzeichnisteil des Pfads zurück " > 2. dirname(); – Gibt den Verzeichnisteil des Pfads zurück
4. filetype(); – Rufen Sie den Dateityp ab " > 4. filetype(); – Rufen Sie den Dateityp ab
5. fstat() und stat();
6、filesize();--取得文件大小" >  6、filesize();--取得文件大小
   7、disk_free_space(); -- 返回目錄中的可用空間
  8、disk_total_space(); --返回一個目錄的磁盤總大小
9、fopen($filepath,$mode) " >  9、fopen($filepath,$mode) 
10、file();--把整個文件讀入一個數(shù)組中" >   10、file();--把整個文件讀入一個數(shù)組中
將整個文件讀入一個字符串" >  11、file_get_contents();-- 將整個文件讀入一個字符串
  12、fgets();--從文件指針中讀取一行
  14、fseek();--在文件指針中定位
15、flock();--輕便的咨詢文件鎖定 " >  15、flock();--輕便的咨詢文件鎖定 
  16、is_readable --判斷給定文件名是否可讀" >  16、is_readable --判斷給定文件名是否可讀
17、is_writeable -- 判斷給定的文件名是否可寫" >  17、is_writeable -- 判斷給定的文件名是否可寫
  18、chown(); -- 改變文件的所有者" >  18、chown(); -- 改變文件的所有者
二、目錄函數(shù)
  1、is_dir();--判斷給定文件名是否是一個目錄
  2、mkdir();--新建目錄
3、opendir();--打開目錄句柄" >  3、opendir();--打開目錄句柄
  4、readdir();--從目錄句柄中讀取條目" >  4、readdir();--從目錄句柄中讀取條目
Heim php教程 php手冊 Organisiert allgemeine PHP-Dateifunktionen und Verzeichnisfunktionen

Organisiert allgemeine PHP-Dateifunktionen und Verzeichnisfunktionen

Sep 02, 2016 am 08:42 AM

1. H?ufig verwendete Dateifunktionsbibliothek

1. basename(); – Gibt den Dateinamenteil des Pfads zurück.

<span style="color: #0000ff;">string</span> <span style="color: #008080;">basename</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$path</span> [, <span style="color: #0000ff;">string</span> <span style="color: #800080;">$suffix</span><span style="color: #000000;"> ] )
//給出一個包含有指向一個文件的全路徑的字符串,本函數(shù)返回基本的文件名。</span>

 Parameter: path Ein Pfad. Unter Windows k?nnen sowohl Schr?gstriche (/) als auch Backslashes () als Verzeichnistrennzeichen verwendet werden. In anderen Umgebungen ist es ein Schr?gstrich (/)

 suffix Wenn der Dateiname mit suffix endet, wird auch dieser Teil entfernt.

Rückgabewert: Gibt den Basisdateinamen von path zurück.

<span style="color: #800080;">$path</span> = 'd:/test/test.txt'<span style="color: #000000;">;

</span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">basename</span>(<span style="color: #800080;">$path</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">echo</span> "<br>"<span style="color: #000000;">;
</span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">basename</span>(<span style="color: #800080;">$path</span>,'.txt');


2. dirname(); – Gibt den Verzeichnisteil des Pfads zurück

<span style="color: #0000ff;">string</span> <span style="color: #008080;">dirname</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$path</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">給出一個包含有指向一個文件的全路徑的字符串,本函數(shù)返回去掉文件名后的目錄名。</span>

 Parameter: path,Ein Pfad. Unter Windows k?nnen sowohl Schr?gstriche (/) als auch Backslashes () als Verzeichnistrennzeichen verwendet werden. In anderen Kontexten ist es ein Schr?gstrich (/).

Rückgabewert : Gibt das übergeordnete Verzeichnis des Pfads zurück. Wenn path keinen Schr?gstrich enth?lt, wird ein Punkt ('.') zurückgegeben, der das aktuelle Verzeichnis angibt. Andernfalls sind die zurückgegebenen Zeichen die Zeichen nach dem Entfernen der Endung path /component (der letzte Schr?gstrich und der folgende Teil) in Zeichenfolge.

<span style="color: #800080;">$path</span> = 'd:/test/test.txt'<span style="color: #000000;">;

</span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">basename</span>(<span style="color: #800080;">$path</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">echo</span> "<br>"<span style="color: #000000;">;
</span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">basename</span>(<span style="color: #800080;">$path</span>,'.txt'<span style="color: #000000;">);
</span><span style="color: #0000ff;">echo</span> "<br>"<span style="color: #000000;">;
</span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">dirname</span>(<span style="color: #800080;">$path</span>);


3. pathinfo(); --Dateipfadinformationen zurückgeben

<span style="color: #0000ff;">mixed</span> <span style="color: #008080;">pathinfo</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$path</span> [, int <span style="color: #800080;">$options</span> = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION |<span style="color: #000000;"> PATHINFO_FILENAME ] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">pathinfo() 返回一個關(guān)聯(lián)數(shù)組包含有 path 的信息。返回關(guān)聯(lián)數(shù)組還是字符串取決于 options。</span>
  <strong><span style="font-size: 16px;">參數(shù)</span></strong><span class="genanchor"><span class="Apple-converted-space"><span style="font-size: 16px;"><strong>:</strong> <code class="parameter">path </code></span><code class="parameter"> </code></span></span><span style="font-size: 16px;">要解析的路徑。<br />     </span><code class="parameter"><span style="font-size: 16px;">options</span> </code><span style="font-size: 16px;">如果指定了,將會返回指定元素;它們包括:<code>PATHINFO_DIRNAME</code>,<code>PATHINFO_BASENAME</code><span class="Apple-converted-space"> 和<code>PATHINFO_EXTENSION</code><span class="Apple-converted-space"> 或<span class="Apple-converted-space"> <code>PATHINFO_FILENAME</code>。</span></span></span>如果沒有指定</span><span class="Apple-converted-space"><span style="font-size: 16px;"> <code class="parameter">options</code></span><span class="Apple-converted-space"><span style="font-size: 16px;"> 默認是返回全部的單元。<br />  <strong>返回值:</strong>如果沒有傳入<span class="Apple-converted-space"> <code class="parameter">options</code><span class="Apple-converted-space"> ,將會返回包括以下單元的數(shù)組<span class="Apple-converted-space"> <span class="type">array:<em>dirname</em>,<em>basename</em><span class="Apple-converted-space"> 和<span class="Apple-converted-space"> <em>extension</em>(如果有),以 及<em>filename</em>。</span></span></span></span></span></span>   <br /></span></span></span>
<span style="color: #800080;">$path</span> = 'd:/test/test.txt'<span style="color: #000000;">;
</span><span style="color: #008080;">var_dump</span>(<span style="color: #008080;">pathinfo</span>(<span style="color: #800080;">$path</span>));


4. filetype(); – Rufen Sie den Dateityp ab

<span style="color: #0000ff;">string</span> <span style="color: #008080;">filetype</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">返回文件的類型。</span>
  <strong><span style="font-size: 16px;">參數(shù)</span></strong>: <span style="font-size: 16px;"><code class="parameter">filename </code>文件</span><span style="font-size: 16px;">的路徑。</span>
<span style="font-size: 16px;"><strong>  返回值</strong></span>: <span style="font-size: 16px;">返回文件的類型。 可能的值有 fifo,char,dir,block,link,file 和 unknown。如果出錯則返回</span><span class="Apple-converted-space"><span style="font-size: 16px;"> <code>FALSE</code>。如果 stat 調(diào)用失敗或者文件類型未知的話</span><span class="Apple-converted-space"><span style="font-size: 16px;"> </span><span class="function"><span style="font-size: 16px;">filetype()</span><span class="Apple-converted-space"><span style="font-size: 16px;"> 還會產(chǎn)生一個</span><span class="Apple-converted-space"><span style="font-size: 16px;"> <code>E_NOTICE</code></span><span class="Apple-converted-space"><span style="font-size: 16px;"> 消息。</span></span></span></span></span></span></span>
<span style="color: #800080;">$path</span> = 'd:/test/test.txt'<span style="color: #000000;">;
</span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">filetype</span>(<span style="color: #800080;">$path</span><span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;">結(jié)果file</span>


5. fstat() und stat();

  ⑴, fstat() – Dateiinformationen über den ge?ffneten Dateizeiger abrufen

<span style="color: #0000ff;">array</span> <span style="color: #008080;">fstat</span> ( <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$handle</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">獲取由文件指針 handle 所打開文件的統(tǒng)計信息。本函數(shù)和 stat() 函數(shù)相似,除了它是作用于已打開的文件指針而不是文件名。</span>

  Parameter: <code class="parameter"><span style="font-size: 16px;"> handle</span> handle Der Dateisystemzeiger wird normalerweise durch dargestellt fopen() erstellte Ressource (Ressource).

?Rückgabewert: Gibt ein Array mit statistischen Informationen für die Datei zurück. Das Format des Arrays wird auf der Seite stat() im Handbuch beschrieben.

?、? stat() – gibt Dateiinformationen

<span style="color: #0000ff;">array</span> <span style="color: #008080;">stat</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">獲取由 filename 指定的文件的統(tǒng)計信息。如果 filename 是符號連接,則統(tǒng)計信息是關(guān)于被連接文件本身的,而不是符號連接。
//lstat() 和 stat() 相同,只除了它會返回符號連接的狀態(tài)。</span>

 :filename ParameterDer Pfad zur Datei.

<span style="color: #800080;">$path</span> = 'd:/test/test.txt'<span style="color: #000000;">;

</span><span style="color: #800080;">$fp</span> = <span style="color: #008080;">fopen</span>("d:/test/test.txt","r"<span style="color: #000000;">);
</span><span style="color: #800080;">$fstat</span> = <span style="color: #008080;">fstat</span>(<span style="color: #800080;">$fp</span><span style="color: #000000;">);
</span><span style="color: #008080;">fclose</span>(<span style="color: #800080;">$fp</span><span style="color: #000000;">);
</span><span style="color: #008080;">var_dump</span>(<span style="color: #800080;">$fstat</span>);


  6、filesize();--取得文件大小

int <span style="color: #008080;">filesize</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">取得指定文件的大小。</span>

  參數(shù):filename 文件的路徑。

  返回值:返回文件大小的字節(jié)數(shù),如果出錯返回 FALSE 并生成一條 E_WARNING 級的錯誤。

<?<span style="color: #000000;">php

</span><span style="color: #008000;">//</span><span style="color: #008000;"> 輸出類似:test.txt:   bytes</span>

<span style="color: #800080;">$filename</span> = 'd:/test/test.txt'<span style="color: #000000;">;
</span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$filename</span> . ': ' . <span style="color: #008080;">filesize</span>(<span style="color: #800080;">$filename</span>) . ' bytes'<span style="color: #000000;">;

</span>?>
<span style="color: #008000;">//</span><span style="color: #008000;">結(jié)果:d:/test/test.txt: 12 bytes</span>


  7、disk_free_space(); -- 返回目錄中的可用空間

<span style="color: #0000ff;">float</span> <span style="color: #008080;">disk_free_space</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$directory</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">給出一個包含有一個目錄的字符串,本函數(shù)將根據(jù)相應(yīng)的文件系統(tǒng)或磁盤分區(qū)返回可用的字節(jié)數(shù)。</span>

  <span style="font-size: 16px;">參數(shù):directory</span> 文件系統(tǒng)目錄或者磁盤分區(qū)。

<span style="color: #008080;">header</span>("Content-Type:Text/html;charset=utf8"<span style="color: #000000;">);
</span><span style="color: #800080;">$path</span> = 'd:/test/test.txt'<span style="color: #000000;">;
</span><span style="color: #800080;">$df</span> = <span style="color: #008080;">disk_free_space</span>("d:/"<span style="color: #000000;">);
</span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$df</span>."字節(jié)";


  8、disk_total_space(); --返回一個目錄的磁盤總大小

<span style="color: #0000ff;">float</span> <span style="color: #008080;">disk_total_space</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$directory</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">給出一個包含有一個目錄的字符串,本函數(shù)將根據(jù)相應(yīng)的文件系統(tǒng)或磁盤分區(qū)返回所有的字節(jié)數(shù)。 【譯者注】本函數(shù)返回的是該目錄所在的磁盤分區(qū)的總大小,因此在給出同一個磁盤分區(qū)的不同目錄作為參數(shù)所得到的結(jié)果完全相同。 在 Unix 和 Windows 200x/XP 中都支持將一個磁盤分區(qū)加載為一個子目錄,這時正確使用本函數(shù)就很有意義。</span>

  參數(shù):directory 文件系統(tǒng)的目錄或者磁盤分區(qū)


  9、fopen($filepath,$mode) 

<span style="color: #0000ff;">resource</span> <span style="color: #008080;">fopen</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span> , <span style="color: #0000ff;">string</span> <span style="color: #800080;">$mode</span> [, bool <span style="color: #800080;">$use_include_path</span> = <span style="color: #0000ff;">false</span> [, <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$context</span><span style="color: #000000;"> ]] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">fopen() 將 filename 指定的名字資源綁定到一個流上</span>

 Parameter: Dateiname Wenn filename das Format ?scheme://...“ hat, wird es behandelt als URL. PHP sucht nach einem Protokollhandler (auch als Wrapper-Protokoll bekannt), um diesen Modus zu verarbeiten. Wenn das Wrapper-Protokoll nicht für das Protokoll registriert wurde, gibt PHP eine Meldung aus, um bei der Suche nach potenziellen Problemen im Skript zu helfen und filename als zu behandeln ein normaler Dateiname. Machen Sie weiter.

 

fopen() mode 的可能值列表
mode說明
'r' 只讀方式打開,將文件指針指向文件頭。
'r ' 讀寫方式打開,將文件指針指向文件頭。
'w' 寫入方式打開,將文件指針指向文件頭并將文件大小截為零。如果文件不存在則嘗試創(chuàng)建之。
'w ' 讀寫方式打開,將文件指針指向文件頭并將文件大小截為零。如果文件不存在則嘗試創(chuàng)建之。
'a' 寫入方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創(chuàng)建之。
'a ' 讀寫方式打開,將文件指針指向文件末尾。如果文件不存在則嘗試創(chuàng)建之。
'x' 創(chuàng)建并以寫入方式打開,將文件指針指向文件頭。如果文件已存在,則 fopen() 調(diào)用失敗并返回 FALSE,并生成一條 E_WARNING 級別的錯誤信息。如果文件不存在則嘗試創(chuàng)建之。這和給 底層的 open(2) 系統(tǒng)調(diào)用指定 O_EXCL|O_CREAT 標記是等價的。
'x ' 創(chuàng)建并以讀寫方式打開,其他的行為和 'x' 一樣。
fopen() in Liste m?glicher Werte für Modus
ModusBeschreibung
'r' Im schreibgeschützten Modus ?ffnen und den Dateizeiger auf den Dateikopf verweisen.
'r ' Im Lese-/Schreibmodus ?ffnen und den Dateizeiger auf den Dateiheader verweisen.
'w' ?ffnen Sie den Schreibmodus, richten Sie den Dateizeiger auf den Dateikopf und kürzen Sie die Dateigr??e auf Null. Wenn die Datei nicht vorhanden ist, versuchen Sie, sie zu erstellen.
'w ' ?ffnen Sie im Lese-/Schreibmodus, zeigen Sie mit dem Dateizeiger auf den Dateiheader und kürzen Sie die Dateigr??e auf Null. Wenn die Datei nicht vorhanden ist, versuchen Sie, sie zu erstellen.
'a' ?ffnen Sie im Schreibmodus und zeigen Sie mit dem Dateizeiger auf das Ende der Datei. Wenn die Datei nicht vorhanden ist, versuchen Sie, sie zu erstellen.
'a ' ?ffnen Sie im Lese-/Schreibmodus und zeigen Sie mit dem Dateizeiger auf das Ende der Datei. Wenn die Datei nicht vorhanden ist, versuchen Sie, sie zu erstellen.
'x' Erstellen und zum Schreiben ?ffnen, wobei der Dateizeiger auf den Dateikopf zeigt. Wenn die Datei bereits vorhanden ist, schl?gt der Aufruf von fopen() fehl und gibt FALSE< zurück /strong> und generieren Sie eine Fehlermeldung der Stufe E_WARNING. Wenn die Datei nicht vorhanden ist, versuchen Sie, sie zu erstellen. Dies entspricht der Angabe des Flags O_EXCL|O_CREAT für den zugrunde liegenden Systemaufruf open(2).
'x ' wird im Lese-/Schreibmodus erstellt und ge?ffnet. Andere Verhaltensweisen sind die gleichen wie 'x' .
<?<span style="color: #000000;">php
</span><span style="color: #800080;">$handle</span> = <span style="color: #008080;">fopen</span>("/home/rasmus/file.txt", "r"<span style="color: #000000;">);
</span><span style="color: #800080;">$handle</span> = <span style="color: #008080;">fopen</span>("/home/rasmus/file.gif", "wb"<span style="color: #000000;">);
</span><span style="color: #800080;">$handle</span> = <span style="color: #008080;">fopen</span>("http://www.example.com/", "r"<span style="color: #000000;">);
</span><span style="color: #800080;">$handle</span> = <span style="color: #008080;">fopen</span>("ftp://user:password@example.com/somefile.txt", "w"<span style="color: #000000;">);
</span>?>


  10、file();--把整個文件讀入一個數(shù)組中

<span style="color: #0000ff;">array</span> <span style="color: #008080;">file</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span> [, int <span style="color: #800080;">$flags</span> = 0 [, <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$context</span><span style="color: #000000;"> ]] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">把整個文件讀入一個數(shù)組中。</span>

  參數(shù):filename 文件的路徑。

     flags 可選參數(shù) flags 可以是以下一個或多個常量:

     1、<strong>FILE_USE_INCLUDE_PATH</strong> include_path 中查找文件。 2、<strong>FILE_IGNORE_NEW_LINES</strong> 在數(shù)組每個元素的末尾不要添加換行符 3、<strong>FILE_SKIP_EMPTY_LINES</strong> 跳過空行。

     <span style="font-size: 16px;">context 一個上下文資源,創(chuàng)建<span class="function">stream_context_create()</span>函數(shù)。</span>

<?<span style="color: #000000;">php
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 將一個文件讀入數(shù)組。本例中通過 HTTP 從 URL 中取得 HTML 源文件。</span>
<span style="color: #800080;">$lines</span> = <span style="color: #008080;">file</span>('http://www.example.com/'<span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 在數(shù)組中循環(huán),顯示 HTML 的源文件并加上行號。</span>
<span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$lines</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$line_num</span> => <span style="color: #800080;">$line</span><span style="color: #000000;">) {
    </span><span style="color: #0000ff;">echo</span> "Line #<b>{<span style="color: #800080;">$line_num</span>}</b> : " . <span style="color: #008080;">htmlspecialchars</span>(<span style="color: #800080;">$line</span>) . "<br />\n"<span style="color: #000000;">;
}
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 另一個例子將 web 頁面讀入字符串。參見 file_get_contents()。</span>
<span style="color: #800080;">$html</span> = <span style="color: #008080;">implode</span>('', <span style="color: #008080;">file</span>('http://www.example.com/'<span style="color: #000000;">));
</span><span style="color: #008000;">//</span><span style="color: #008000;"> 從 PHP 5 開始可以使用可選標記參數(shù)</span>
<span style="color: #800080;">$trimmed</span> = <span style="color: #008080;">file</span>('somefile.txt', FILE_IGNORE_NEW_LINES |<span style="color: #000000;"> FILE_SKIP_EMPTY_LINES);
</span>?>


  11、file_get_contents();-- 將整個文件讀入一個字符串

<span style="color: #0000ff;">string</span> <span style="color: #008080;">file_get_contents</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span> [, bool <span style="color: #800080;">$use_include_path</span> = <span style="color: #0000ff;">false</span> [, <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$context</span> [, int <span style="color: #800080;">$offset</span> = -1 [, int <span style="color: #800080;">$maxlen</span><span style="color: #000000;"> ]]]] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">和 file() 一樣,只除了 file_get_contents() 把文件讀入一個字符串。將在參數(shù) offset 所指定的位置開始讀取長度為 maxlen 的內(nèi)容。如果失敗,file_get_contents() 將返回 FALSE。</span>

  參數(shù):filename: 要讀取的文件的名稱。

     use_include_path:As of PHP 5 the FILE_USE_INCLUDE_PATH can be used to trigger include path search.

     context:A valid context resource created with stream_context_create(). 如果你不需要自定義 context,可以用 NULL 來忽略。

<span style="color: #008080;">header</span>("Content-Type:Text/html;charset=utf8"<span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"> <= PHP 5</span>
<span style="color: #800080;">$file</span> = <span style="color: #008080;">file_get_contents</span>('d:/test/test.txt', <span style="color: #0000ff;">true</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$file</span>.'<br>'<span style="color: #000000;">;
</span><span style="color: #008000;">//</span><span style="color: #008000;"> > PHP 5</span>
<span style="color: #800080;">$file</span> = <span style="color: #008080;">file_get_contents</span>('d:/test/test.txt',<span style="color: #000000;"> FILE_USE_INCLUDE_PATH);
</span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$file</span><span style="color: #000000;">;
</span><span style="color: #008000;">//</span><span style="color: #008000;">結(jié)果
//this is test
//this is test</span>

  


  12、fgets();--從文件指針中讀取一行

<span style="color: #0000ff;">string</span> <span style="color: #008080;">fgets</span> ( <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$handle</span> [, int <span style="color: #800080;">$length</span><span style="color: #000000;"> ] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">從文件指針中讀取一行。</span>

  參數(shù):handle:文件指針必須是有效的,必須指向由 fopen() fsockopen() 成功打開的文件(并還未由 fclose() 關(guān)閉)。

  length:從 handle 指向的文件中讀取一行并返回長度最多為 length - 1 字節(jié)的字符串。碰到換行符(包括在返回值中)、EOF 或者已經(jīng)讀取了 length - 1 字節(jié)后停止(看先碰到那一種情況)。如果沒有指定length,則默認為 1K,或者說 1024 字節(jié)。

 


  13、ftell();-- 返回文件指針讀/寫的位置

int <span style="color: #008080;">ftell</span> ( <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$handle</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">返回由 handle 指定的文件指針的位置,也就是文件流中的偏移量。</span>

  參數(shù):handle : 文件指針必須是有效的,且必須指向一個通過 fopen() popen() 成功打開的文件。在附加模式(加參數(shù) "a" 打開文件)中 ftell() 會返回未定義錯誤。

<span style="color: #008080;">header</span>("Content-Type:Text/html;charset=utf8"<span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"> opens a file and read some data</span>
<span style="color: #800080;">$fp</span> = <span style="color: #008080;">fopen</span>("d:/test/test.txt", "r"<span style="color: #000000;">);
</span><span style="color: #800080;">$data</span> = <span style="color: #008080;">fgets</span>(<span style="color: #800080;">$fp</span>, 4<span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"> where are we ?</span>
<span style="color: #0000ff;">echo</span> <span style="color: #008080;">ftell</span>(<span style="color: #800080;">$fp</span>); <span style="color: #008000;">//</span><span style="color: #008000;"> 結(jié)果3</span>
<span style="color: #008080;">fclose</span>(<span style="color: #800080;">$fp</span>);


  14、fseek();--在文件指針中定位

int <span style="color: #008080;">fseek</span> ( <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$handle</span> , int <span style="color: #800080;">$offset</span> [, int <span style="color: #800080;">$whence</span> =<span style="color: #000000;"> SEEK_SET ] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">在與 handle 關(guān)聯(lián)的文件中設(shè)定文件指針位置。 新位置從文件頭開始以字節(jié)數(shù)度量,是以 whence 指定的位置加上 offset。</span>

  參數(shù) :handle:文件系統(tǒng)指針,是典型地由 fopen() 創(chuàng)建的 resource(資源)。

      offset:偏移量。要移動到文件尾之前的位置,需要給 offset 傳遞一個負值,并設(shè)置 whence SEEK_END。

     whence values are: 1、SEEK_SET - 設(shè)定位置等于 offset 字節(jié)。2、SEEK_CUR - 設(shè)定位置為當(dāng)前位置加上 offset。2、SEEK_END - 設(shè)定位置為文件尾加上 <span style="font-size: 16px;">offset。</span>

<span style="color: #008080;">header</span>("Content-Type:Text/html;charset=utf8"<span style="color: #000000;">);
</span><span style="color: #800080;">$fp</span> = <span style="color: #008080;">fopen</span>('d:\test\test.txt', 'r'<span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"> read some data</span>
<span style="color: #800080;">$data</span> = <span style="color: #008080;">fgets</span>(<span style="color: #800080;">$fp</span>, 4096<span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;"> move back to the beginning of the file
// same as rewind($fp);</span>
 <span style="color: #008080;">fseek</span>(<span style="color: #800080;">$fp</span>, 0);


  15、flock();--輕便的咨詢文件鎖定 

bool <span style="color: #008080;">flock</span> ( <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$handle</span> , int <span style="color: #800080;">$operation</span> [, int &<span style="color: #800080;">$wouldblock</span><span style="color: #000000;"> ] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">flock() 允許執(zhí)行一個簡單的可以在任何平臺中使用的讀取/寫入模型(包括大部分的 Unix 派生版和甚至是 Windows)。</span>

  參數(shù):handle 文件系統(tǒng)指針,是典型地由 fopen() 創(chuàng)建的 resource(資源)。

      operation 可以是以下值之一:1、LOCK_SH取得共享鎖定(讀取的程序)。2、LOCK_EX 取得獨占鎖定(寫入的程序。3、LOCK_UN 釋放鎖定(無論共享或獨占)。

           如果不希望 flock() 在鎖定時堵塞,則是 LOCK_NB(Windows 上還不支持)。

     wouldblock:如果鎖定會堵塞的話(EWOULDBLOCK 錯誤碼情況下),可選的第三個參數(shù)會被設(shè)置為 TRUE。(Windows 上不支持)

<span style="color: #0000ff;">if</span> (<span style="color: #008080;">flock</span>(<span style="color: #800080;">$fp</span>, LOCK_EX)) {  <span style="color: #008000;">//</span><span style="color: #008000;"> 進行排它型鎖定</span>
    <span style="color: #008080;">ftruncate</span>(<span style="color: #800080;">$fp</span>, 0);      <span style="color: #008000;">//</span><span style="color: #008000;"> truncate file</span>
    <span style="color: #008080;">fwrite</span>(<span style="color: #800080;">$fp</span>, "Write something here\n"<span style="color: #000000;">);
    </span><span style="color: #008080;">fflush</span>(<span style="color: #800080;">$fp</span>);            <span style="color: #008000;">//</span><span style="color: #008000;"> flush output before releasing the lock</span>
    <span style="color: #008080;">flock</span>(<span style="color: #800080;">$fp</span>, LOCK_UN);    <span style="color: #008000;">//</span><span style="color: #008000;"> 釋放鎖定</span>
} <span style="color: #0000ff;">else</span><span style="color: #000000;"> {
    </span><span style="color: #0000ff;">echo</span> "Couldn't get the lock!"<span style="color: #000000;">;
}

</span><span style="color: #008080;">fclose</span>(<span style="color: #800080;">$fp</span>);


  16、is_readable --判斷給定文件名是否可讀

bool <span style="color: #008080;">is_readable</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">判斷給定文件名是否存在并且可讀。</span>

  參數(shù):filename:文件的路徑。

  返回值:如果由 filename 指定的文件或目錄存在并且可讀則返回 TRUE,否則返回 FALSE。 

<span style="color: #800080;">$filename</span> = 'd:\test\test.txt'<span style="color: #000000;">;
</span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">is_readable</span>(<span style="color: #800080;">$filename</span><span style="color: #000000;">)) {
    </span><span style="color: #0000ff;">echo</span> 'The file is readable'<span style="color: #000000;">;
} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
    </span><span style="color: #0000ff;">echo</span> 'The file is not readable'<span style="color: #000000;">;
}
</span><span style="color: #008000;">//</span><span style="color: #008000;">The file is readable</span>


  17、is_writeable -- 判斷給定的文件名是否可寫

bool <span style="color: #008080;">is_writable</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">如果文件存在并且可寫則返回 TRUE。filename 參數(shù)可以是一個允許進行是否可寫檢查的目錄名。</span>

  參數(shù):filename 要檢查的文件名稱。

<span style="color: #800080;">$filename</span> = 'd:\test\test.txt'<span style="color: #000000;">;
</span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">is_writeable</span>(<span style="color: #800080;">$filename</span><span style="color: #000000;">)) {
    </span><span style="color: #0000ff;">echo</span> 'The file is writeable'<span style="color: #000000;">;
} </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
    </span><span style="color: #0000ff;">echo</span> 'The file is not writeable'<span style="color: #000000;">;
}
</span><span style="color: #008000;">//</span><span style="color: #008000;">The file is writeable</span>


  18、chown(); -- 改變文件的所有者

bool <span style="color: #008080;">chown</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span> , <span style="color: #0000ff;">mixed</span> <span style="color: #800080;">$user</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">嘗試將文件 filename 的所有者改成用戶 user(由用戶名或用戶 ID 指定)。 只有超級用戶可以改變文件的所有者。</span>

  參數(shù):filename:文件路徑。

     user:用戶名或數(shù)字。


二、目錄函數(shù)

  1、is_dir();--判斷給定文件名是否是一個目錄

bool <span style="color: #008080;">is_dir</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$filename</span><span style="color: #000000;"> )
</span><span style="color: #008000;">//</span><span style="color: #008000;">判斷給定文件名是否是一個目錄。</span>

  參數(shù):filename:如果文件名存在并且為目錄則返回 TRUE。如果 filename 是一個相對路徑,則按照當(dāng)前工作目錄檢查其相對路徑。

<span style="color: #800080;">$filename</span> = 'd:\test\test.txt'<span style="color: #000000;">;
</span><span style="color: #008080;">var_dump</span>(<span style="color: #008080;">is_dir</span>('$filename'));    <span style="color: #008000;">//</span><span style="color: #008000;">bool(false) </span>
<span style="color: #008080;">var_dump</span>(<span style="color: #008080;">is_dir</span>('d:\test'));        <span style="color: #008000;">//</span><span style="color: #008000;">bool(true)</span>


  2、mkdir();--新建目錄

bool <span style="color: #008080;">mkdir</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$pathname</span> [, int <span style="color: #800080;">$mode</span> = 0777 [, bool <span style="color: #800080;">$recursive</span> = <span style="color: #0000ff;">false</span> [, <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$context</span> ]]] )<br />//嘗試新建一個由 pathname 指定的目錄。

  參數(shù):pathname:目錄的路徑。

  mode:默認的 mode 是 0777,意味著最大可能的訪問權(quán)。有關(guān) mode 的更多信息請閱讀 chmod() 頁面。

<span style="color: #008080;">mkdir</span>("d:/test/test1", 0700);


  3、opendir();--打開目錄句柄

<span style="color: #0000ff;">resource</span> <span style="color: #008080;">opendir</span> ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$path</span> [, <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$context</span><span style="color: #000000;"> ] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">打開一個目錄句柄,可用于之后的 closedir(),readdir() 和 rewinddir() 調(diào)用中。</span>

  參數(shù):path 要打開的目錄路徑

     context 參數(shù)的說明見手冊中的 Streams API 一章。


  4、readdir();--從目錄句柄中讀取條目

<span style="color: #0000ff;">string</span> <span style="color: #008080;">readdir</span> ([ <span style="color: #0000ff;">resource</span> <span style="color: #800080;">$dir_handle</span><span style="color: #000000;"> ] )
</span><span style="color: #008000;">//</span><span style="color: #008000;">返回目錄中下一個文件的文件名。文件名以在文件系統(tǒng)中的排序返回。</span>

  參數(shù):dir_handle 目錄句柄的 resource,之前由 opendir() 打開

<span style="color: #008080;">header</span>("Content-Type:Text/html;charset=utf8"<span style="color: #000000;">);
</span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$handle</span> = <span style="color: #008080;">opendir</span>('d:/test'<span style="color: #000000;">)) {
    </span><span style="color: #0000ff;">echo</span> "Directory handle: <span style="color: #800080;">$handle</span>\n"<span style="color: #000000;">;
    </span><span style="color: #0000ff;">echo</span> "Files:\n"<span style="color: #000000;">;

    </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 這是正確地遍歷目錄方法 </span><span style="color: #008000;">*/</span>
    <span style="color: #0000ff;">while</span> (<span style="color: #0000ff;">false</span> !== (<span style="color: #800080;">$file</span> = <span style="color: #008080;">readdir</span>(<span style="color: #800080;">$handle</span><span style="color: #000000;">))) {
        </span><span style="color: #0000ff;">echo</span> "<span style="color: #800080;">$file</span>\n"<span style="color: #000000;">;
    }

    </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 這是錯誤地遍歷目錄的方法
    while ($file = readdir($handle)) {
        echo "$file\n";
    }
    </span><span style="color: #008000;">*/</span>
    <span style="color: #008080;">closedir</span>(<span style="color: #800080;">$handle</span><span style="color: #000000;">);
}</span>

?


Erkl?rung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Hei?e KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem v?llig kostenlosen KI-Gesichtstausch-Tool aus!

Hei?e Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Hei?e Themen

PHP-Tutorial
1502
276