Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.