<p>Using PHP's <code>file_exists</code> function is perfectly fine for checking this.</p>
<pre class="lang-php prettyprint-override"><code>$exists = file_exists($path);
</code></pre>

CC BY-SA 4.0
2022-07-26T07:57:17.333Z
2022-07-26T07:57:17.333Z
Ben Croker
<p>If I have an asset resource, loaded successfully from the database, whose corresponding file no longer exists on its Volume (irrespective of Volume type), what is the best way to find out if the file exists, in PHP?</p>
<p><code>file_exists</code> or maybe <code>is_file</code>?</p>
<p>Or is there an inbuilt method in Craft I should be using?</p>
<p>Any help appreciated!</p>

<plugin-development><assets><php>
What's the correct way to check that an asset file exists?
# What's the correct way to check that an asset file exists?

(Asked by: username_0 on 2022-04-13)

If I have an asset resource, loaded successfully from the database, whose corresponding file no longer exists on its Volume (irrespective of Volume type), what is the best way to find out if the file exists, in PHP?

`file_exists` or maybe `is_file`?

Or is there an inbuilt method in Craft I should be using?

Any help appreciated!

**Tags:** plugin-development, assets, php


---

## 1 answers

### Answer by username_1 on 2022-07-26. Score: 2

Using PHP's file_exists function is perfectly fine for checking this.
$exists = file_exists($path);


---

