Last active
October 19, 2023 00:50
-
-
Save BruceMcKinnon/d7d0d4dba1518ae3bde4963dd8cce4d1 to your computer and use it in GitHub Desktop.
Check if a file in the WP uploads folder actually does exist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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