A brief introduction to the method of obtaining file attributes in PHP_PHP tutorial

WBOY
Release: 2016-07-15 13:34:31
Original
1151 people have browsed it

PHP Get file attributes to get the latest modification time:

<ol class="dp-xml"><li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">file</span><span> = </span><span class="attribute-value">'test.txt'</span><span>;  </span></li><li class="alt"><span>echo date('r', <br />filemtime($file));  </span></li><li><span class="tag">?></span><span> </span></span></li></ol>
Copy after login

Return Speaking of Unix timestamps, this is commonly used in caching technology.

Related PHP acquisition of file attributes also includes obtaining the last access time fileatime(), filectime() when the file permissions, owner, owner The time when the metadata in the group or other inodes is updated, the fileowner() function returns the file owner

$owner = posix_getpwuid(fileowner($file));

(non-window system), ileperms() gets the permissions of the file,

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">file</span><span> = </span><span class="attribute-value">'dirlist.php'</span><span>;  </span></li><li class="alt"><span>$</span><span class="attribute">perms</span><span> = </span><span class="attribute-value">substr</span><span>(sprintf<br />('%o', fileperms($file))<br />, -4);  </span></li><li><span>echo $perms;  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li>
<li><span> </span></li>
</ol>
Copy after login

filesize() returns the number of bytes of the file size:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>// 输出类似:somefile.txt:<br /> 1024 bytes  </span></li><li class="alt"><span>$</span><span class="attribute">filename</span><span> = </span><span class="attribute-value">'somefile.txt'</span><span>;  </span></li><li><span>echo $filename . ': ' <br />. filesize($filename) . ' bytes';  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li>
<li><span> </span></li>
</ol>
Copy after login

PHP has a function stat() function that returns an array to get all the information about file attributes:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">file</span><span> = </span><span class="attribute-value">'dirlist.php'</span><span>;  </span></li><li class="alt"><span>$</span><span class="attribute">perms</span><span> = </span><span class="attribute-value">stat</span><span>($file);  </span></li><li><span>var_dump($perms);  </span></li><li class="alt"><span class="tag">?></span><span> </span></span></li>
<li><span> </span></li>
</ol>
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445971.htmlTechArticlePHP gets file attributes to get the latest modification time: ?php $ file = 'test.txt' ; echodate(' r', filemtime($file)); ? Returns the unix timestamp, which is commonly used in caching technology. Related PHP acquisition...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!