WordPress.com 到 WordPress.org 迁移:如何下载 wp-content 文件夹?

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

让我们假设官方 WordPress Import/Export 插件不能在每个主机和本地主机上运行。让我们假设可以导入帖子,但不能导入媒体。假设 WordPress.com 不提供从其站点免费下载所有媒体的可能性。

http://example.com/ 目前托管在 WordPress.com

大量上传的图片是这样托管的:

https://example.files.wordpress.com/2014/11/1.png https://example.files.wordpress.com/2015/11/1.png 等等....

可能性 1:有没有一种工具可以下载博客上托管的所有图片,同时保留文件夹结构(我还没有找到)。

可能性 2:是否可以使用 XML 导出文件从 WordPress.com 下载所有媒体(尤其是图像),但没有官方的 WordPress 导入工具(无需编写自定义文件) XML 文件的解析器)。

在数据库上使用简单的 search/replace 就可以替换数据库中的主机并上传提取的图像。也欢迎更好的解决方案。

使用以下脚本解决了这个问题。这可能对遇到同样问题的每个人都有帮助:

(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";

}