/** * Recursively deletes a directory. * @param string $path a directory. * @since 3.3 */ function wpbdp_rrmdir($path) { if (!is_dir($path)) { return; } $files = wpbdp_scandir($path); foreach ($files as &$f) { $filepath = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($f, DIRECTORY_SEPARATOR); if (is_dir($filepath)) { wpbdp_rrmdir($filepath); } else { unlink($filepath); } } rmdir($path); }
private function find_uploaded_files() { $base_dir = $this->get_imports_dir(); $res = array('images' => array(), 'csv' => array()); if (is_dir($base_dir)) { $files = wpbdp_scandir($base_dir); foreach ($files as $f_) { $f = $base_dir . DIRECTORY_SEPARATOR . $f_; if (!is_file($f) || !is_readable($f)) { continue; } switch (strtolower(substr($f, -4))) { case '.csv': $res['csv'][] = $f; break; case '.zip': $res['images'][] = $f; break; default: break; } } } return $res; }
public function cleanup() { $upload_dir = wp_upload_dir(); wpbdp_rrmdir($this->workingdir); if (!$upload_dir['error']) { $csvexportsdir = rtrim($upload_dir['basedir'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'wpbdp-csv-exports'; $contents = wpbdp_scandir($csvexportsdir); if (!$contents) { wpbdp_rrmdir($csvexportsdir); } } }