Import image in a post

  • Unknown's avatar

    I only need a code that import this image (for example) = “http://www.fii.org/fii/imagenes/images/image-2.jpg”
    to the end of this post (for example) /?p=47

    Can you correct this code?
    Thank you very very much

    I find this (don’t work)
    <?php

    $wp_filetype = wp_check_filetype(basename($filename), null );
    $attachment = array(
    ‘post_mime_type’ => $wp_filetype[‘type’],
    ‘post_title’ => preg_replace(‘/.[^.]+$/’, ”, basename($filename)),
    ‘post_content’ => ”,
    ‘post_status’ => ‘inherit’
    );
    $attach_id = wp_insert_attachment( $attachment, $filename, 47);
    // you must first include the image.php file
    // for the function wp_generate_attachment_metadata() to work
    require_once(ABSPATH . “wp-admin” . ‘/includes/image.php’);
    $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    ?>

    The blog I need help with is: (visible only to logged in users)

  • Unknown's avatar
  • Unknown's avatar

    Hi. Since you are handling PHP code, it looks like you have a self-hosted WordPress.ORG blog and are in the wrong forum. Please ask your question on http://wordpress.org/support

    You are currently in a WordPress.COM forum and our answers will not apply to your situation. Thanks and I hope you find a solution to your problem soon.

  • The topic ‘Import image in a post’ is closed to new replies.