Support » How-To and Troubleshooting » [Resolved] How to manually generate thumbnails?

[Resolved] How to manually generate thumbnails?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’ve only ever done this once successfully – via .csv – Here is a link to a script that I used: http://mfields.org/_plugins/mf-csv-import.zip

    I saved the file to the directory where WordPress is installed and ran it through the browser. This script is VERY resource intensive and I was only able to import about 30 records at a time.

    Please note that I’m am only posting this as a reference, the file may or may not work for you, but I hope that it does 🙂

    Thank you, I’ll look into that file this afternoon. It’s good to hear I’m not alone in trying this 🙂

    No problem… I really wish something like this was built into WordPress, but I wish there were a lot of things built into WordPress…. Any way, let me know if you have any problems with this…

    I got this working, albeit differently.. (but thank you for mfields – pouring over your code helped.)

    I embedded SWFUpload into a plugin admin page and used an ajax call to bulk upload the pictures that were formerly on my server and attach them. I figured out that my main problem was using an incorrect path for the $filepath variable.

    The shortened version using Post ID 288 as a test:

    $save_path = “../../uploads/”;
    $file_name = preg_replace(‘/[^’.$valid_chars_regex.’]|\.+$/i’, “”, basename($_FILES[$upload_name][‘name’]));

    move_uploaded_file($_FILES[$upload_name][“tmp_name”], $save_path.$file_name;

    $url = get_bloginfo(‘url’).’/wp-content/uploads/’.$file_name;
    $file = realpath($save_path).’/’.$file_name;

    $attachment = array(
    ‘post_mime_type’ => ‘image/jpeg’,
    ‘guid’ => $url,
    ‘post_parent’ => 288,
    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($file_name)),
    ‘post_content’ => ‘file: ‘.$file.’ url:’.$url

    $id = wp_insert_attachment($attachment, $file, 288);
    wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));

    Footnote: What I meant to say – turning it into an SWFUpload made me realize my mistake of using an incorrect path. Knowing that, it’s probably not too hard to modify to use existing server files. The function realpath() saved me, but simply designating an absolute path to start should work.

    Modded for existing server files instead of upload. Limited to 7 for testing. Hope someone else finds it useful.

    File structure is: /uploads/import/########/image.jpg
    ######## is a secret custom field on each post (_origID)

    $path = realpath(‘../wp-content/uploads/import’);
    $dirs = array_diff(scandir($path),array(‘.’,’..’));


    foreach ($dirs as $ad_number) {
    if (is_dir($path.’/’.$ad_number)) {
    $ad_image_path = $path.’/’.$ad_number;
    $ad_images = array_diff(scandir($ad_image_path),array(‘.’,’..’));


    while (have_posts()) : the_post();

    foreach ($ad_images as $ad_image) {
    $extension = end(explode(‘.’,$ad_image));
    if (strtolower($extension)==’jpg’ && $count<=7) {

    $url = get_bloginfo(‘url’).’/wp-content/uploads/import/’.$ad_number.’/’.$ad_image;
    $file = $ad_image_path.’/’.$ad_image;
    $post_id = get_the_ID();

    // Construct the attachment array
    $attachment = array(
    ‘post_mime_type’ => ‘image/jpeg’,
    ‘guid’ => $url,
    ‘post_parent’ => $post_id,
    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($ad_image)),
    ‘post_content’ => ‘image…’

    // Save the data

    $id = wp_insert_attachment($attachment, $file, $post_id);
    wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));



    This sounds awesome!!! Thanks for posting your fix… I’m totally gonna check this out soon as I need to completely need to rework my portfolio.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] How to manually generate thumbnails?’ is closed to new replies.