_copy_image_file

函式
_copy_image_file ( $attachment_id )
Access
Private
引數
  • (int) $attachment_id Attachment ID.
    Required:
返回值
  • (string|false) New file path on success, false on failure.
定義位置
相關方法
wp_save_image_filewp_crop_imageremove_image_sizewp_get_image_mimehas_image_size
引入
3.4.0
棄用
-

copy_image_file: 這個函式用來複制一個上傳的影象檔案到WordPress的上傳目錄中。它接受一個影象檔名作為其引數,並返回複製檔案的完整路徑。

複製一個現有的影象檔案。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _copy_image_file( $attachment_id ) {
$dst_file = get_attached_file( $attachment_id );
$src_file = $dst_file;
if ( ! file_exists( $src_file ) ) {
$src_file = _load_image_to_edit_path( $attachment_id );
}
if ( $src_file ) {
$dst_file = str_replace( wp_basename( $dst_file ), 'copy-' . wp_basename( $dst_file ), $dst_file );
$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), wp_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;
}
function _copy_image_file( $attachment_id ) { $dst_file = get_attached_file( $attachment_id ); $src_file = $dst_file; if ( ! file_exists( $src_file ) ) { $src_file = _load_image_to_edit_path( $attachment_id ); } if ( $src_file ) { $dst_file = str_replace( wp_basename( $dst_file ), 'copy-' . wp_basename( $dst_file ), $dst_file ); $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), wp_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; }
function _copy_image_file( $attachment_id ) {
	$dst_file = get_attached_file( $attachment_id );
	$src_file = $dst_file;

	if ( ! file_exists( $src_file ) ) {
		$src_file = _load_image_to_edit_path( $attachment_id );
	}

	if ( $src_file ) {
		$dst_file = str_replace( wp_basename( $dst_file ), 'copy-' . wp_basename( $dst_file ), $dst_file );
		$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), wp_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;
}

常見問題

FAQs
檢視更多 >