diff --git a/core/includes/file.inc b/core/includes/file.inc index 0e69bfe..9e62b9f 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -2119,6 +2119,33 @@ function file_get_mimetype($uri, $mapping = NULL) { } /** + * Returns a file object which can be passed to file_save(). + * + * @param $uri + * A string containing the URI, path, or filename. + * @return + * A file object, or FALSE on error. + */ +function file_uri_to_object($uri) { + $uri = file_stream_wrapper_uri_normalize($uri); + $files = entity_load('file', FALSE, array('uri' => $uri)); + $file = !empty($files) ? reset($files) : FALSE; + if (!$file) { + global $user; + $file = new stdClass(); + $file->uid = $user->uid; + $file->filename = 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; +} + +/** * Sets the permissions on a file or directory. * * This function will use the 'file_chmod_directory' and 'file_chmod_file'