Skip to content

Instantly share code, notes, and snippets.

@BruceMcKinnon
Last active October 19, 2023 00:50
Show Gist options
  • Save BruceMcKinnon/d7d0d4dba1518ae3bde4963dd8cce4d1 to your computer and use it in GitHub Desktop.
Save BruceMcKinnon/d7d0d4dba1518ae3bde4963dd8cce4d1 to your computer and use it in GitHub Desktop.
Check if a file in the WP uploads folder actually does exist
// Take the URL of a local file in the WP Uploads folder and check that it does actually exist
function uploaded_file_exists( $url ) {
$local_exists = false;
if ( $url ) {
$uploads = wp_upload_dir();
$local_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
$local_exists = file_exists($local_path);
}
return $local_exists;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment