diff --git includes/file.inc includes/file.inc index d4fc50a..8410308 100644 --- includes/file.inc +++ includes/file.inc @@ -1719,6 +1719,28 @@ 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) { + global $user; + $uri = file_stream_wrapper_uri_normalize($uri); + $wrapper = file_stream_wrapper_get_instance_by_uri($uri); + $file = new StdClass; + $file->uid = $user->uid; + $file->filename = basename($uri); + $file->uri = $uri; + $file->filemime = file_get_mimetype($uri); + $file->filesize = filesize($uri); + $file->status = FILE_STATUS_PERMANENT; + return $file; +} + +/** * Set the permissions on a file or directory. * * This function will use the 'file_chmod_directory' and 'file_chmod_file'