How to get list of paths (not urls) for an image

This should achieve what you want, however note that there will be backslashes AND forward slashes in the resulting path name. If this causes a problem on your web server you may need to do a further str_replace to forward slashes with backslashes

See comments in code for more info

$sizes = array_merge(array('full'),get_intermediate_image_sizes());
$uploads = wp_upload_dir();
foreach ($sizes as $imageSize) {
    // Get the image object
    $image_object = wp_get_attachment_image_src($post->ID,$imageSize );
    // Isolate the url
    $image_url = $image_object[0];
    // Using the wp_upload_dir replace the baseurl with the basedir
    $image_path = str_replace( $uploads['baseurl'], $uploads['basedir'], $image_url );
    // echo it out
    echo   $imageSize . ':<br>' .$image_path.'<br>';
}

Leave a Comment