You are here

function _get_dir_file_ids in Ubercart 5

Return a list of file ids that are in the directory

@return: If there are files in the directory an array of file ids, else return FALSE

Parameters

$fid: The file id associated with the directory

$recursive: Whether or not to list recursive directories and their files

3 calls to _get_dir_file_ids()
uc_file_order in uc_file/uc_file.module
Implementation of hook_order().
_file_table_action in uc_file/uc_file.module
Perform a specified action on the uc_files table
_user_table_action in uc_file/uc_file.module
Perform a specified action on the uc_file_users table

File

uc_file/uc_file.module, line 1418
Allows products to be associated with downloadable files.

Code

function _get_dir_file_ids($fid, $recursive = FALSE) {
  $fids = array();
  $dir = db_result(db_query("SELECT filename FROM {uc_files} WHERE fid = %d", $fid));
  $files = db_query("SELECT * FROM {uc_files} WHERE filename LIKE LOWER('%s')", $dir . '%');
  while ($file = db_fetch_object($files)) {
    $filename_change = str_replace($dir, '', $file->filename);
    $filename = substr($filename_change, 0, 1) == '/' ? substr($filename_change, 1) : $filename_change;
    if (!strpos($filename, '/') && !empty($filename)) {
      $fids[] = $file->fid;
    }
    elseif ($recursive && !empty($filename) && $filename_change != $file->filename) {
      $fids[] = $file->fid;
    }
  }
  return empty($fids) ? FALSE : $fids;
}