<?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>klainfo &#187; php</title>
	<atom:link href="http://www.klainfo.com/category/web/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.klainfo.com</link>
	<description>Web2.0, HPC, Unix, and my mine.</description>
	<lastBuildDate>Mon, 30 Aug 2010 15:45:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>[PHP] Delete Apache owned files and folders</title>
		<link>http://www.klainfo.com/2010/01/24/php-delete-apache-owned-files-and-folders/</link>
		<comments>http://www.klainfo.com/2010/01/24/php-delete-apache-owned-files-and-folders/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 05:22:55 +0000</pubDate>
		<dc:creator>klainfo</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[permission]]></category>

		<guid isPermaLink="false">http://blog.klainfo.com/?p=586</guid>
		<description><![CDATA[เนื่องจากผมใช้ Doku wiki แล้ว Apache มันสร้าง cache ขึ้นมาเอง แล้วผมอยากจะลบมัน ปรากฏว่าผมลบไฟล์ไม่ได้ เนื่องจากผมไม่ใช่ Root แล้วเป็นไฟล์ที่ Apache สร้างขึ้นด้วย นั่งขุดคุ้ยหา script php มาลบให้มันละกัน ทำตามนี้โลด 1 2 3 4 5 6 7 8 9 10 11 12 13 14 &#60;?php function SureRemoveDir&#40;$dir&#41; &#123; if&#40;!$dh = @opendir&#40;$dir&#41;&#41; return; while &#40;&#40;$obj = readdir&#40;$dh&#41;&#41;&#41; &#123; if&#40;$obj==‘.’ &#124;&#124; $obj==‘..’&#41; continue; if &#40;!@unlink&#40;$dir.‘/’.$obj&#41;&#41; &#123; SureRemoveDir&#40;$dir.‘/’.$obj&#41;;]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.klainfo.com%2F2010%2F01%2F24%2Fphp-delete-apache-owned-files-and-folders%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.klainfo.com%2F2010%2F01%2F24%2Fphp-delete-apache-owned-files-and-folders%2F&amp;source=klainfo&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>เนื่องจากผมใช้ Doku wiki แล้ว Apache มันสร้าง cache ขึ้นมาเอง แล้วผมอยากจะลบมัน ปรากฏว่าผมลบไฟล์ไม่ได้ เนื่องจากผมไม่ใช่ Root แล้วเป็นไฟล์ที่ Apache สร้างขึ้นด้วย</p>
<p>นั่งขุดคุ้ยหา script php มาลบให้มันละกัน ทำตามนี้โลด</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> SureRemoveDir<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$dh</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">opendir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #990000;">readdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dh</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #339933;">==</span>‘<span style="color: #339933;">.</span>’ <span style="color: #339933;">||</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">==</span>‘<span style="color: #339933;">..</span>’<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!@</span><span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span>‘<span style="color: #339933;">/</span>’<span style="color: #339933;">.</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
SureRemoveDir<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span>‘<span style="color: #339933;">/</span>’<span style="color: #339933;">.</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                   <span style="color: #000088;">$file_deleted</span><span style="color: #339933;">++;</span>
            <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">rmdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$dir_deleted</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>วิธีเรียกใช้ก็ง่ายๆ ตามนี้เลยครับ โดยใส่ชื่อ Directory ลงไปแทนคำว่า Test</p>
<p>เสร็จแล้ว เย่ๆ ^^</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://www.klainfo.com/2010/01/24/php-delete-apache-owned-files-and-folders/" target="_blank"><img src="http://www.klainfo.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.klainfo.com/2010/01/24/php-delete-apache-owned-files-and-folders/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
