1.20.x file.test FileTestHelper::getFileByFilename($filename, $reset = FALSE)

Get a file from the database based on its filename.

Parameters

$filename: A file filename, usually generated by $this->randomName().

$reset: (optional) Whether to reset the internal file_load() cache.

Return value

A file object matching $filename.:

File

modules/file/tests/file.test, line 55
Tests for file.module.

Class

FileTestHelper
Provides methods specifically for testing File module's field handling.

Code

function getFileByFilename($filename, $reset = FALSE) {
  $files = file_load_multiple(array(), array('filename' => $filename), $reset);
  // Load the first file returned from the database.
  $returned_file = reset($files);
  return $returned_file;
}