《php基礎教程》——四檔案和目錄 學習總結

來源:互聯網
上載者:User
《php基礎教程》——4檔案和目錄 學習總結
一、寫入檔案:
$fp = fopen(filename, mode);
mode 為開啟檔案方式比如 ‘a+’表示讀寫檔案,檔案不存在則建立,新資料主加到檔案尾部

fwrite($fp,寫入內容);

fclose($fp);

二、鎖定檔案:當有多個使用者同時對檔案操作時保證不出現衝突

fclock($fp, 鎖定類型); //鎖定類型包括寫入獨享、讀取共用……

三、讀取檔案:

$data = file('檔案路徑');

將讀取的資料放到data數組內,每個元素為檔案的一行。

編碼測試:ws.php:

    test    data[0]:\n ' .$data[0]. '

';}else{print 'please enter your quotation';}}?>

This is the foot of the document


測試裁圖:

起始:


結果:




五、處理檔案上傳:

1.form標籤必須包含:enctype="multipart/form-data",表單必須用post方法

2.必須添加一個隱藏輸入框,建議瀏覽器最大上傳檔案大小(以位元組計)

3.建立表單欄位

代碼測試:ws.php:

    test   your file is upload!

';}else{$errors = $_FILES['thefile']['error'];print $errors;}}?>

This is the foot of the document


六、目錄

1.導航目錄:

尋找目錄中所有內容:scandir();

eg: $stuff = scandir('目錄名');//函數返回一個數組,包含目錄中的檔案和目錄,複製給$stuff

2.建立目錄:

mkdir( '路徑名' );


  • 聯繫我們

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