_copy_image_file
Copy an existing image file.
Description
(string|false) _copy_image_file( (string) $attachment_id );
Returns (string|false)
New file path on success, false on failure.
Parameters (1)
- 0. $attachment_id (string)
- The attachment id.
Usage
if ( !function_exists( '_copy_image_file' ) ) { require_once ABSPATH . '/wp-admin/includes/image.php'; } // The attachment id. $attachment_id = ''; // NOTICE! Understand what this does before running. $result = _copy_image_file($attachment_id);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/image.php
- function _copy_image_file( $attachment_id ) {
- $dst_file = $src_file = get_attached_file( $attachment_id );
- if ( ! file_exists( $src_file ) )
- $src_file = _load_image_to_edit_path( $attachment_id );
- if ( $src_file ) {
- $dst_file = str_replace( basename( $dst_file ), 'copy-' . basename( $dst_file ), $dst_file );
- $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) );
- /**
- * The directory containing the original file may no longer
- * exist when using a replication plugin.
- */
- wp_mkdir_p( dirname( $dst_file ) );
- if ( ! @copy( $src_file, $dst_file ) )
- $dst_file = false;
- } else {
- $dst_file = false;
- }
- return $dst_file;
- }