WordPress.com to WordPress.org migration: How to download the wp-content folder?

Lets assume the official WordPress Import/Export Plugin does not work on every host as well as on localhost. Lets assume it is possible to import the posts, but not the media. Lets assume WordPress.com does not offer a free possibility to download all the media from their site.

http://example.com/ is currently hosted on WordPress.com

Read More

Tons of uploaded images are hosted like this:

https://example.files.wordpress.com/2014/11/1.png
https://example.files.wordpress.com/2015/11/1.png
and so on….

Possibility 1: Is there a Tool which can download all the images hosted on the blog while preserving the folder structure (I did not find one yet).

Possibility 2: Is there a possibility to download all media (especially images) from WordPress.com with the XML export files, but without the official WordPress Importer Tool (without having to write a custom parser for the XML-files).

With a simple search/replace on the database one could replace the host in the database and upload the extracted images. A better solution is welcome, too.

Related posts

1 comment

  1. Solved this with the following script. This may be helpful for everybody having the same problem:

    (index.php)

    <?php include('functions.php'); ?>
    <!DOCTYPE html>
    <!--
    To change this license header, choose License Headers in Project Properties.
    To change this template file, choose Tools | Templates
    and open the template in the editor.
    -->
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
        <body>
            <form action="#" method="post" enctype="multipart/form-data">
              Choose the XML export file from WordPress.com (one-by-one). Execute the script with the same file until you see "success":<br> 
                <input name="myfile" type="file" size="50" accept="text/*"> 
              </p>  
              <button type="submit">... go download em all!</button>
            </form>
        </body>
    </html>
    

    (functions.php)

    <?php
    
    if (isset($_FILES['myfile']) && ($_FILES['myfile']['error'] == UPLOAD_ERR_OK)) {
        // $xml = simplexml_load_file($_FILES['myfile']['tmp_name']); 
    
        $filestr = file_get_contents($_FILES['myfile']['tmp_name']);
        $matches = null;
        $returnValue = preg_match_all('/https:\/\/mydomain.files.wordpress.com\/[0-9]{4}\/[0-9]{2}\/[^<>\/]+(\.jpg|.png|.gif|.jpeg|.bmp)/',$filestr,$matches);
    
    
    
        foreach($matches[0] as $image_url) {
            $rep = str_replace("https://mydomin.files.wordpress.com",'',$image_url);
            $save_path = "/images".$rep;
    
            // if not image already downloaded
            if(!file_exists(dirname(__FILE__).$save_path)) {
                $img_only = strrchr($save_path,"/");
                $path = dirname(__FILE__).str_replace($img_only,"",$save_path);
                if(!is_dir($path)) {
                    mkdir($path, 0777,true);
                }
                file_put_contents(dirname(__FILE__).$save_path, fopen($image_url, 'r'));
            }
        }
        // if not reached, repeat the script
        echo "success";
    
    }
    

Comments are closed.