PHP 檔案操作函數大全

來源:互聯網
上載者:User

標籤:style   blog   color   os   檔案   資料   div   時間   

<?php    讀取檔案夾:        $handler = opendir("c:\");//開啟檔案夾        while($dir = readdir($handler)){//遍曆檔案夾            echo $dir;        }        讀取檔案夾:        $handler = dir("c:/");//開啟檔案夾        while(false !== ($entry = $handler->read())){//遍曆檔案夾            echo $entry;        }        $handler->close();//關閉控制代碼        判斷是否有讀的許可權 is_readable($file);    判斷檔案是否存在 file_exists($file);    擷取檔案所有內容 file_get_contents($file);        擷取檔案所有內容        $handler = fopem($file,‘r‘);//擷取檔案控制代碼        $data = fread($handler,filesize($file));//擷取檔案所有內容,第二個參數代表取多少位元組        fclose($handler);//銷毀控制代碼        讀取二進位檔案 $data = implode(‘‘,file($file));    判斷是否有寫的許可權 is_writable($file);    寫檔案內容 file_put_content($file);        寫檔案內容        $handler = fopen($file,‘w‘);//擷取檔案控制代碼        fwrite($handler,$data);//寫資料        fclose($handler);        鎖    $handler = fopen($file,‘w‘);    flock($handler,LOCK_EX);//為檔案申請拍它型鎖    fwrite($handler,$data);//寫資料    flock($handler,LOCK_UN);//釋放鎖    fclose($handler);        刪除檔案 unlink($file);    複製檔案 copy($file,$newfile);參數1為被複製的檔案,參數2為複製到的檔案    重新命名檔案夾 rename();        時間    擷取檔案最後一次修改時間 filemtime    擷取檔案最後一次訪問時間 fileatime    擷取檔案所有者 fileowner        擷取檔案位元組大小 filesize($file);        擷取檔案的全部資訊 stat($file);?>

 

聯繫我們

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