Codex tools: Log in
Contents |
Download an image from the specified URL and attach it to a post.
<?php media_sideload_image($file, $post_id, $desc); ?>
<?php $url = "http://s.wordpress.org/style/images/wp3-logo.png"; $post_id = 1; $desc = "The WordPress Logo"; $image = media_sideload_image($url, $post_id, $desc); ?>
Since: 2.6.0
media_sideload_image() is located in wp-admin/includes/media.php.
If you want to use this function outside of the context of /wp-admin/ (typically if you are writing a more advanced custom importer script) you need to include media.php and depending includes:
require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); require_once(ABSPATH . 'wp-admin/includes/image.php');
the_attachment_link(), get_attachment_link(), wp_get_attachment_link(), wp_get_attachment_image(), wp_get_attachment_image_src(), wp_get_attachment_url(), wp_get_attachment_thumb_file(), wp_get_attachment_thumb_url(), is_attachment(), wp_get_attachment_metadata()