• Resolved Xeross

    (@x3r0ss)


    Hey,

    I’m working on a script that can post stuff from outside wordpress.
    However the following ain’t working.

    $post = array(
    	"post_title" => $posttitle,
    	"post_content" => $content,
    	"post_status" => "draft",
    	"post_author" => 1,
    	"post_category" => array(9, 10),
    	"tags_input" => array($show, $title, 'TV Show'),
    	"post_type" => "post",
    );
    
    $post_id = wp_insert_post( $post );
    
    $image = file_get_contents($image);
    file_put_contents("/data/www/blogfreestuff/public_html/tools/hulu/image.jpg", $image);
    $image = "/data/www/blogfreestuff/public_html/tools/hulu/image.jpg";
    echo $image;
    
    $attachment = array(
    	"post_title" => $show . " - " . $title . "(Thumb)",
    	"post_content" => "",
    	"post_status" => "draft");
    
    $id = wp_insert_attachment($attachment , $image, $post_id );
    wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $image ) );

    It sais wp_generate_attachment_metadata doesn’t exist, so I included the file that contained the function, the error is gone, but the attachment gets inserted without image.

    So can anyone help me out ?

    Thanks, Xeross

    Edit: I forgot i’m using wpmu

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Xeross

    (@x3r0ss)

    Update

    `$post = array(
    “post_title” => $posttitle,
    “post_content” => $content,
    “post_status” => “draft”,
    “post_author” => 1,
    “post_category” => array(9, 10),
    “tags_input” => “$show, $title, TV Show”,
    “post_type” => “post”,
    );

    $post_id = wp_insert_post( $post );
    $image = “/data/www/blogfreestuff/public_html/tools/hulu/image.jpg”;
    file_put_contents($image, file_get_contents($imageurl));

    if(!file_exists($image))
    exit(“No File”);

    $attachment = array(
    “post_title” => $show . ” – ” . $title . “(Thumb)”,
    “post_content” => “”,
    “post_status” => “draft”,
    “post_mime_type” => “image/jpeg”
    );

    $id = wp_insert_attachment($attachment, $image, $post_id );

    $metadata = wp_generate_attachment_metadata( $id, $image );

    $result = wp_update_attachment_metadata( $id, $metadata );`

    Thread Starter Xeross

    (@x3r0ss)

    Solved :D:D:D

    It would be useful if you could post your fix! Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Upload File Through PHP, Error or Empty attachment.’ is closed to new replies.