<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>filesize &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/filesize/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Mon, 01 Oct 2012 09:26:57 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>
	<item>
		<title>PHP计算文件夹总文件大小</title>
		<link>https://www.mudbest.com/%e8%ae%a1%e7%ae%97%e6%96%87%e4%bb%b6%e5%a4%b9%e5%a4%a7%e5%b0%8f/</link>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Fri, 26 Aug 2011 10:11:25 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[filesize]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=781</guid>

					<description><![CDATA[或许指定的一个文件的全部文件的累计大小。 使用：]]></description>
										<content:encoded><![CDATA[<p>或许指定的一个文件的全部文件的累计大小。<span id="more-781"></span></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
function getDirSize($dir) {
	$handle = opendir ( $dir );
	while ( false !== ($FolderOrFile = readdir ( $handle )) ) {
		if ($FolderOrFile != &quot;.&quot; &amp;&amp; $FolderOrFile != &quot;..&quot;) {
			if (is_dir ( &quot;$dir/$FolderOrFile&quot; )) {
				$sizeResult += getDirSize ( &quot;$dir/$FolderOrFile&quot; );
			} else {
				$sizeResult += filesize ( &quot;$dir/$FolderOrFile&quot; );
			}
		}
	}
	closedir ( $handle );
	return $sizeResult;
}

// 单位自动转换函数
function getRealSize($size) {
	$kb = 1024; // Kilobyte
	$mb = 1024 * $kb; // Megabyte
	$gb = 1024 * $mb; // Gigabyte
	$tb = 1024 * $gb; // Terabyte
	

	if ($size &lt; $kb) {
		return $size . &quot; B&quot;;
	} else if ($size &lt; $mb) {
		return round ( $size / $kb, 2 ) . &quot; KB&quot;;
	} else if ($size &lt; $gb) {
		return round ( $size / $mb, 2 ) . &quot; MB&quot;;
	} else if ($size &lt; $tb) {
		return round ( $size / $gb, 2 ) . &quot; GB&quot;;
	} else {
		return round ( $size / $tb, 2 ) . &quot; TB&quot;;
	}
}
?&gt;
</pre>
<p>使用：</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
echo getRealSize ( getDirSize ( dirname ( $_SERVER &#x5B;'SCRIPT_FILENAME'] )  ) );
?&gt;
</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
