get_attached_file [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Retrieve attached file path based on attachment ID.
You can optionally send it through the 'get_attached_file' filter, but by default it will just return the file path unfiltered.
The function works by getting the single post meta name, named '_wp_attached_file' and returning it. This is a convenience function to prevent looking up the meta name and provide a mechanism for sending the attached filename through a filter.
Source
<?php
function get_attached_file( $attachment_id, $unfiltered = false ) {
$file = get_post_meta( $attachment_id, '_wp_attached_file', true );
// If the file is relative, prepend upload dir
if ( $file && 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
$file = $uploads['basedir'] . "/$file";
if ( $unfiltered )
return $file;
return apply_filters( 'get_attached_file', $file, $attachment_id );
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/get attached file « WordPress Codex
You can optionally send it through the 'get_attached_file' filter, but by default it will just return the file path unfiltered. The function works by getting the single post ...
codex.wordpress.org - WordPress › Support » get_attached_file() returns wrong path?
Hey,. I'm trying to use get_attached_file() in my new plugin to find out the complete path of an uploaded file based on its ID. But get_attached_file seems to only ...
wordpress.org - #18855 (get_attached_file( $post_id ) wrongly(?) returns the ...
The function get_attached_file( $post_id ) wrongly(?) returns the uploads directory when $post_id is not a valid attachment. For example, if I run the following ...
core.trac.wordpress.org - get_attached_file Wordpress hook details -- Adam Brown, BYU ...
Applied to the attached file information retrieved by the get_attached_file function . Filter function arguments: file information, attachment ID. This description was ...
adambrown.info