unlink and folder removal php


There were several problems I have had with removing a folder in php

  • cannot remove folders that contain files, php has no recursive
  • after scandir, a foreach loop with if(!=) to remove '.' and '..' failed
2015-10-07 07:21:47gstlouis

references: http://www.electrictoolbox.com/php-scandir-find-files/

This formula worked

You needed to do an array_diff() to remove the . and ..

ex. $files = array_diff(scandir($path.'/'), array('.', '..'));

2015-10-07 07:24:57