• EnglishMike

    (@stringfold)


    Hi Spencer,

    Thanks for the plugin — found it very useful when migrating my blogs to a multisite installation.

    In my case, I had already moved the attachment files around on my server, which meant I had to modify the plugin a little to get it to work for me. It’s just a few additional lines of code which checks to see whether the files are already in place in the upload area before attempting to upload them from the client.

    Here’s the code: (in process_attachment())


    $filename = explode('/uploads/', $post['url']);
    $fullname = wp_upload_dir();
    $fullname = $fullname['basedir'].'/'.$filename[1];

    if (file_exists($fullname)) {
    $upload['file'] = $fullname;
    $updir = wp_upload_dir();
    $upload['url'] = $updir['baseurl'].'/'.$filename[1];
    } else {
    $upload = fetch_remote_file( $url, $post );
    }

    You’re welcome to use the code in your plugin (no attribution necessary), if you think it’s a good idea. It will allow users with access to their server to reattach files to their posts without having to download and upload all of them during a migration between blogs.

    As it stands, the code will only process files that are within the upload directory for the site. Not sure if you would want to make the code handle files stored elsewhere, and I only tested the code to the point where I got it working for me, so no guarantees!

    Cheers,

    Mike Walker

    https://wordpress.org/plugins/attachment-importer/

  • The topic ‘Enhancement to plugin — handle preinstalled files’ is closed to new replies.