PHP_File檔案操作簡單常用函數

來源:互聯網
上載者:User

標籤:style   color   io   ar   檔案   sp   on   c   html   

php測試檔案

<?php
header("Content-type:text/html;charest=utf-8");
$fileDir=‘Upload/File/content.txt‘;
echo ‘檔案路徑:‘.$fileDir.‘<br/>‘;
echo ‘路徑目錄|dirname():‘.dirname($fileDir).‘<br/>‘;
echo ‘路徑檔案名稱|basename():‘.basename($fileDir).‘<br/>‘;
echo ‘檔案類型|filetype():‘.filetype($fileDir).‘<br/>‘;
echo ‘檔案大小|filesize():‘.filesize($fileDir).‘<br/>‘;
echo ‘檔案修改時間|filemtime():‘.filemtime($fileDir).‘<br/>‘;

echo ‘<br/>‘;
echo ‘絕對路徑|realpath():‘.realpath($fileDir).‘<br/>‘;
echo ‘以數組形式返迴路徑資訊|pathinfo():<br/>‘;
print_r(pathinfo($fileDir));echo ‘<br/>‘;
echo ‘<br/>‘;

echo ‘複製並重新命名檔案|rename(url01,url02):返回‘.copy($fileDir,‘./Upload/renameContent.txt‘).‘<br/>‘;
echo ‘複製檔案|copy(url01,url02):返回‘.copy($fileDir,‘./Upload/copyContent.txt‘).‘<br/>‘;
echo ‘刪除檔案|unlink(url):返回‘[email protected](‘./Upload/unlinkContent.txt‘).‘<br/>‘;

echo ‘<br/>‘;
echo ‘將檔案資訊以字串形式讀取出來|file_get_contents(url):<br/>‘;
echo file_get_contents($fileDir).‘<br/>‘;
$putContent=‘hello word!‘;
echo ‘將字串寫入檔案,檔案不存在自動建立,目錄必須存在,|file_put_contents(url,str)返迴文件大小:‘;
echo file_put_contents(‘./Upload/file_put_contents.txt‘,$putContent).‘<br/>‘;
?>

 

php返回結果

檔案路徑:Upload/File/content.txt
路徑目錄|dirname():Upload/File
路徑檔案名稱|basename():content.txt
檔案類型|filetype():file
檔案大小|filesize():27
檔案修改時間|filemtime():1411488282

絕對路徑|realpath():D:\Kuaipan\www\TestPhp\Upload\File\content.txt
以數組形式返迴路徑資訊|pathinfo():
Array ( [dirname] => Upload/File [basename] => content.txt [extension] => txt [filename] => content )

複製並重新命名檔案|rename(url01,url02):返回1
複製檔案|copy(url01,url02):返回1
刪除檔案|unlink(url):返回

將檔案資訊以字串形式讀取出來|file_get_contents(url):
?hello word! bad word!!!
將字串寫入檔案,檔案不存在自動建立,目錄必須存在,|file_put_contents(url,str)返迴文件大小:11

 

 

PHP_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.