Need help? Check out our Support site, then


How to import a LARGE hosted wordpress into wordpress.com

  1. Dear all,

    My brother and I spent 12 hours working on uploading a 60 MB WML XML file from an old hosted WordPress site to WordPress.com. Here we post the solution

    The problem: A 60 MB WML, and wordpress.com upload limit is 3 MB!.

    We needed to chunk our WML, so we created a nifty PHP script that makes this happen. We share the love. It will create a bunch of files called chunk_*.xml that you will need to manually upload to wordpress.com under Manage... Import.

    The PHP script is pasted below our signature.

    Because of memory and CPU limitations (to avoid 500-errors) run it locally either by using XAMPP on your Windows machine (Daniel's favorite), or just instaling php-cli on your beautiful Ubuntu box (Alan's favorite), and doing php index.php

    Of course, you have to name your exported xml file to: XMLFINAL.xml

    Daniel and Alan, your saviours.

    <?php

    //Strings

    $header = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
    "<rss version=\"2.0\"
    xmlns:content=\"http://purl.org/rss/1.0/modules/content/\"
    xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\"
    xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
    xmlns:wp=\"http://wordpress.org/export/1.0/\">

    <channel>
    <title>Noemí Guzik Glantz</title>
    <link>http://noemi.guzikglantz.com</link&gt;
    <description>Día a día...</description>
    <pubDate>Mon, 21 Jan 2008 02:52:20 +0000</pubDate>
    <generator>http://wordpress.org/?v=2.5.1</generator&gt;
    <language>en</language>
    <wp:wxr_version>1.0</wp:wxr_version>
    <wp:base_site_url>http://noemi.guzikglantz.com</wp:base_site_url&gt;
    <wp:base_blog_url>http://noemi.guzikglantz.com</wp:base_blog_url&gt;
    <wp:category><wp:category_nicename>general</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name><![CDATA[General]]></wp:cat_name></wp:category>";

    $footer = "</channel></rss>";

    //load xml document
    $dom = new DomDocument();
    $dom->load("XMLFINAL.xml");

    //create DOMXPath object
    $xpath = new Domxpath($dom);

    //$query the document
    $result = $xpath->query("//item");

    $i = 1;

    $posts = 15;

    $files_chunk = 1;

    //loop through the result (it's a NamedNodemap..)
    foreach ($result as $title) {

    echo "iterando nodo " . $i . "
    " ;
    if ($i == 1) {
    echo "ENTRANDO A NEW DOCUMENT

    ";
    $chunkXML = new DomDocument('1.0');
    $root = $chunkXML->createElement('root');
    $root = $chunkXML->appendChild($root);
    }

    $ni = $chunkXML->importNode($title, true);
    $root->appendChild($ni);

    if ($i == $posts) {

    echo "deberia escribir file ". $files_chunk . "\n";

    //$chunkXML->save("chunk_" . $files_chunk . ".xml");
    $stringXML = $chunkXML->saveXML();

    $stringXML = str_replace("<root>", "", $stringXML);
    $stringXML = str_replace("</root>", "", $stringXML);
    $stringXML = str_replace("<?xml version=\"1.0\"?>", "", $stringXML);
    $stringXML = str_replace("<item xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:wp=\"http://wordpress.org/export/1.0/\">", "\n<item>", $stringXML);

    $stringXML = $header . $stringXML . $footer;

    $fh = fopen("chunk_" . $files_chunk . ".xml", 'w');
    fwrite($fh, $stringXML);
    fclose($fh);

    //$chunkXML = undefined ;
    $i = 0;

    $files_chunk++;
    }

    $i++;
    }

    ?>

  2. Wow.. interesting post! Gonna try this out!

Topic Closed

This topic has been closed to new replies.

About this Topic