AdLemons | Contacto

Registrarse | Entrar

How to migrate pictures from WordPress.com to WordPress.org

Escrito por Miguel Angel Ivars Mas en Uncategorized · Tuesday 5 de November de 2013 ·
How to migrate pictures from WordPress.com to WordPress.org

How to migrate pictures from WordPress.com to WordPress.org

When migrating a blog from WordPress.com to WordPress.org, if blog entries include images, as is increasingly common, problems sometimes arise when transferring pictures from one blog to another correctly when migrating.

At the time of migration, WordPress plugin can not find the images of the original url, either because we have redirected the domain prematurely, either because we have changed the url in the “xml” export before uploading and the matter do not exist in the future location yet, or because there has been a temporary loss of source server, or simply because they are so many that you cut the import script execution maxed because of being so large the amount of content to transfer, etc. In such cases, we need a plan B to retrieve the images.

If the blog has little time of existence, and so few items, or do not usually include images in the post, maybe manually can be downloaded one by one from WordPress.com to your computer and re-upload to the new server. Otherwise, it can be hell or simply impossible task, so I’ll try to explain an alternative method that I have discovered from Kaspars Dambis to make this a fairly automated action.

Taking the xml file with the exported content, so copy it to a folder within our local web server and rename it as export.xml

In that same folder, create a php file with this content:

$a = array();
$x = simplexml_load_file('export.xml');

foreach ( $x->channel->item as $item )
        if ( $wp = $item->children('http://wordpress.org/export/1.2/') )
                if ( $wp->post_type == 'attachment' )
                        $a[] = $wp->attachment_url;

file_put_contents( 'urls.txt', implode( "\n", $a ) );

This php script will take from the xml and extract all url of the attached images and stored in a new txt file named: urls.txt in the same folder.

Then execute the following command in the command line:

$ xargs -n 1 wget -p -nc < urls.txt

With it, we take every url stored in the newly created file automatically urls.txt and all images are stored in the local folder to be created with the original structure of wordpress.com, so upload them to our server blog will copy and paste only once all its contents inside the folder wp-content/uploads /.

If we work with MAC probably will not have wget installed, but Carlos Burgués explained in this tutorial how to install wget on OS X without the help of Homebrew or Macports.

Another alternative is to use curl:

$ xargs -n 1 curl -O < urls.txt

But keep in mind that curl will not keep the original folder structure of the images to download.

When finished and before importing the xml to the new blog, should change with the option to search and replace any text editor all the urls of the images, so that this structure will:

http://myoldblog.files.wordpress.com/2013/04/img_0316.jpg

To this one:

http://mynewblog.com/2013/04/img_0316.jpg

Thus we would have the file ready to import xml pointing to the new location of the images, where just uploaded on the new server.

The only question to be considered in this method, is that despite work perfectly as I tested, does not affect in any way the database, which is using the WordPress Media Library, so not have access via the Library to use from there in the future these same photos because the database is not aware they exist. But being old photos, this in principle should not be big problem. And if so, can insert them into the post using directly the url of the image.

I hope you have been useful for this tutorial to migrate images from WordPress.com to WordPress.org and so share it so others can take advantage of it too.

  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Digg
  • HackerNews
  • Tumblr
  • Suggest to Techmeme via Twitter
  • Meneame
  • del.icio.us
  • StumbleUpon
  • Google Bookmarks
  • RSS
  • PDF
  • Print
  • email
Subscribe To Comments: Blog de AdLemons, noreply@adlemons.com, activado, Notifícame de los siguientes comentarios por correo, Estás suscrito a los comentarios de este post. Gestionar tus suscripciones. , Eres el autor de este post. Gestionar tus suscripciones., desactivado, [theme_path]/header.php,
,
What Would Seth Godin Do:

Si eres nuevo por aquí, y te interesa lo que lees, podrías suscribirte al feed RSS. ¡Gracias por tu visita!

Comentarios

Una respuesta en “How to migrate pictures from WordPress.com to WordPress.org”

  1. Alex Vasquez en May 3rd, 2014 19:56

    This was perfect! Just what I needed. Fortunately I use Homebrew and was able to pull down wget. =)

Responder




2016 (C) Efectividads Socials Ads S.L. - Todos los derechos reservados.