Home >Backend Development >PHP Tutorial >PHP删除文件夹内及其文件
<p>function Delete($path){</p><p> if (is_dir($path) === true)</p><p> {</p><p> $files = array_diff(scandir($path), array('.', '..'));</p><p> foreach ($files as $file)</p><p> {</p><p> Delete(realpath($path) . '/' . $file);</p><p> }</p><p> return rmdir($path);</p><p> }</p><p> else if (is_file($path) === true)</p><p> {</p><p> return unlink($path);</p><p> }</p><p> return false;</p><p>}</p>
语法:
<p><?php</p><p>$path = "images/";</p><p>Delete($path); // This will delete images folder along with its contents.</p><p>?></p>