常用的file函數

來源:互聯網
上載者:User

著作權聲明:原創作品,允許轉載,轉載時請務必以超連結形式標明文章原始出版、作者資訊和本聲明。否則將追究法律責任。http://blog.csdn.net/mayongzhan - 馬永占,myz,mayongzhan

常用的file函數以下的檔案也可以是url...必須是allow_url_fopen 這兩個不需要fopen()file_get_contents()把檔案讀到字串中file_put_contents()把內容寫到檔案 fopen()開啟檔案feof()檔案是否到結尾fgets()從檔案指標中讀取一行fwrite()寫入檔案fclose()關閉一個已開啟的檔案指標 file_exists()檢查檔案或目錄是否存在unlink()刪除檔案mkdir()建立目錄 <?php/** * @name test.php * @date Sun Jan 20 04:19:06 CST 2008 * @copyright 馬永占(MyZ) * @author 馬永占(MyZ)  * @link http://blog.csdn.net/mayongzhan/ */ header("Content-type: text/html;charset=utf-8"); //檢查檔案或目錄是否存在,建立目錄if (!file_exists('myztest')) {       mkdir('myztest');}//從遠程讀檔案$fp = file_get_contents('http://127.0.0.1/test/test.html');echo htmlspecialchars($fp);//寫到本地file_put_contents('myztest/test.txt',$fp); //開啟檔案$fp = fopen('http://127.0.0.1/test/test.html','rb');$content = '';//判斷檔案是否到結尾,讀檔案while (!feof($fp)) {       $content .= fgets($fp);}//關閉檔案fclose($fp); //開啟檔案$fp = fopen('myztest/test2.txt','wb');//寫到本地fwrite($fp,$content); //刪除檔案//unlink();?>

 

聯繫我們

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