function file_uri_to_object

cis7 file_uri_to_object($uri, $use_existing = TRUE)
cle7 file_uri_to_object($uri, $use_existing = TRUE)
elmsmedia7 file_uri_to_object($uri, $use_existing = TRUE)
icor7 file_uri_to_object($uri, $use_existing = TRUE)
meedjum_blog7 file_uri_to_object($uri, $use_existing = TRUE)
mooc7 file_uri_to_object($uri, $use_existing = TRUE)

Returns a file object which can be passed to file_save().

@todo This should probably be named file_load_by_uri($uri, $create_if_not_exists). @todo Remove this function when is fixed.


string $uri: A string containing the URI, path, or filename.

bool $use_existing: (Optional) If TRUE and there's an existing file in the {file_managed} table with the passed in URI, then that file object is returned. Otherwise, a new file object is returned. Default is TRUE.

Return value

object|bool A file object, or FALSE on error.

5 calls to file_uri_to_object()
file_entity_add_upload_multiple_submit in sites/all/modules/ulmus/file_entity/
Submit handler for the multiple upload form.
file_entity_file_download in sites/all/modules/ulmus/file_entity/file_entity.module
Implements hook_file_download().
MediaInternetFileHandler::getFileObject in sites/all/modules/ulmus/media/modules/media_internet/media_internet.module
Returns a file object which can be used for validation.
MediaInternetFileHandler::preSave in sites/all/modules/ulmus/media/modules/media_internet/media_internet.module
Before the file has been saved, implementors may do additional operations.
media_parse_to_file in sites/all/modules/ulmus/media/media.module
Parse a URL or embed code and return a file object.


sites/all/modules/ulmus/file_entity/, line 691
API extensions of Drupal core's


function file_uri_to_object($uri, $use_existing = TRUE) {
  $file = FALSE;
  $uri = file_stream_wrapper_uri_normalize($uri);

  if ($use_existing) {
    // We should always attempt to re-use a file if possible.
    $files = entity_load('file', FALSE, array('uri' => $uri));
    $file = !empty($files) ? reset($files) : FALSE;

  if (empty($file)) {
    $file = new stdClass();
    $file->uid = $GLOBALS['user']->uid;
    $file->filename = drupal_basename($uri);
    $file->uri = $uri;
    $file->filemime = file_get_mimetype($uri);
    // This is gagged because some uris will not support it.
    $file->filesize = @filesize($uri);
    $file->timestamp = REQUEST_TIME;
    $file->status = FILE_STATUS_PERMANENT;

  return $file;



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.