1 filter.pages.inc _filter_get_file_id($href)

Find a managed file ID from a url.

File

core/modules/filter/filter.pages.inc, line 519
User page callbacks for the Filter module.

Code

function _filter_get_file_id($href) {
  $result = 0;

  // Check URI for valid file scheme.
  if (!file_valid_uri($href)) {
    return $result;
  }

  // Extract file name and directory from $href.
  $pos = strrpos($href, "/");
  $filename = substr($href, $pos + 1);

  // Now find this file name in uri field to get fid.
  if (!empty($filename)) {
    $results = db_select('file_managed')
      ->fields('file_managed', array('fid', 'uri'))
      ->condition('uri', '%' . $filename, 'LIKE')
      ->orderBy('fid', 'DESC')
      ->execute();

    foreach ($results as $found) {
      $result = $found->fid;
    }
  }

  return $result;
}