_wp_relative_upload_path

Return relative path to an uploaded file.

Description

(string) _wp_relative_upload_path( (string) $path ); 

The path is relative to the current upload dir.

Returns (string)

Relative path on success, unchanged path on failure.

Parameters (1)

0. $path (string)
Full path to the file.

Usage

  1. if ( !function_exists( '_wp_relative_upload_path' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Full path to the file. 
  5. $path = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _wp_relative_upload_path($path); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function _wp_relative_upload_path( $path ) { 
  2. $new_path = $path; 
  3.  
  4. $uploads = wp_get_upload_dir(); 
  5. if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) { 
  6. $new_path = str_replace( $uploads['basedir'], '', $new_path ); 
  7. $new_path = ltrim( $new_path, '/' ); 
  8.  
  9. /** 
  10. * Filters the relative path to an uploaded file. 
  11. * @since 2.9.0 
  12. * @param string $new_path Relative path to the file. 
  13. * @param string $path Full path to the file. 
  14. */ 
  15. return apply_filters( '_wp_relative_upload_path', $new_path, $path );