Import images from an old WordPress blog to a new server (or local environment)! This simple script uses wget
to download the file and place it in a corresponding local wp-content/uploads
folder.
WordPress' import script is really dumb when it comes to images - even if you have the box checked to "download and import attachments", it won't actually download any images placed in your post content. This script does the download portion, but and you'll need to update the database separately.
- Update the
urls
array with your list of URLs - Execute the script from your WordPress root:
ruby import-wp-uploads.rb
- Update your database entries to use the new local images
Here's an example SQL command you can run to update all your wp_posts
entries to point to the new local location instead of the old URL you imported from:
UPDATE wp_posts
SET post_content = REPLACE(post_content, 'oldblog.com/wp-content/uploads', 'newblog.com/wp-content/uploads')
WHERE post_type = "post"
Of course, in the above SQL you should update the table name to match your site's prefixing and update the URLs being repalced.