Get fid from file path
@pvorb, you can also use EntityFieldQuery.  See the first comment on https://api.drupal.org/api/drupal/includes%21file.inc/function/file_load_multiple/7 for an example.  Something along the lines of:

$filename = 'myfirstpony.png';
$query = new EntityFieldQuery();
$result = $query-&gt;entityCondition('entity_type', 'file')
  -&gt;propertyCondition('filename', $filename)
  -&gt;execute();
// if you are guaranteed there is exactly one result, then:
$file_object = reset($result['file']);
$fid = $file_object-&gt;fid;
// but beware you might get 0 or many results


If you have more information -- such as the path (from which you can generate a URI) -- then change the query condition to something like -&gt;propertyCondition('uri', 'public://path/to/myfirstpony.png').