You are here

function pdf_using_mpdf_delete_recursive in PDF using mPDF 7.2

Deletes all files and directories in the specified filepath recursively.

If the specified path is a file then it will be passed to file_unmanaged_delete().

Note that this only deletes visible files with write permission.

Parameters

string $folder_pth: A string containing either an URI or a file or directory path.

boolean $delete_permanently: A boolean value indicating wheteher to delete folder permanently or not.

1 call to pdf_using_mpdf_delete_recursive()
pdf_using_mpdf_clear_folder in ./pdf_using_mpdf.install
Removes all pdf file and delete the folder.

File

./pdf_using_mpdf.install, line 110
Removing all PDF set variables and checks for mPDF library existence.

Code

function pdf_using_mpdf_delete_recursive($folder_pth, $delete_permanently = FALSE) {
  $folder_pth = drupal_realpath($folder_pth);
  if (is_dir($folder_pth)) {
    $dir = dir($folder_pth);
    while (($cs_file = $dir
      ->read()) !== FALSE) {

      // condition to avoid deleting of peer folders
      if ($cs_file != '.' && $cs_file != '..') {
        $cs_file_path = $folder_pth . '/' . $cs_file;
        file_unmanaged_delete_recursive($cs_file_path, TRUE);
      }
    }
    $dir
      ->close();
    return $delete_permanently ? drupal_rmdir($folder_pth) : TRUE;
  }
}