For example, we have some image on the external site: http://site.com/image.png
How do I upload this image to my wordpress as an image attachment by php?
Image should be copied to my uploads folder, post added, meta generated.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityFor example, we have some image on the external site: http://site.com/image.png
How do I upload this image to my wordpress as an image attachment by php?
Image should be copied to my uploads folder, post added, meta generated.
You can media_sideload_image()
function to upload your files ex:
$upload = media_sideload_image( $url, $post_id );
or you can use a plugin like Cache Images which uploads all external images to your server as attachments.