3
林试图上传的外部图像和通过PHPWordPress的附件上传
代码即时通讯使用设定如下它作为一个功能的图像,
$photo = new WP_Http();
$photo = $photo->request($article->largeURL);
$attachment = wp_upload_bits($photo_name . '.jpg', null, $photo['body'], date("Y-m", strtotime($photo['headers']['last-modified'])));
$filetype = wp_check_filetype(basename($attachment['file']), null);
$postinfo = array(
'post_mime_type' => $filetype['type'],
'post_title' => $article->heading . ' ',
'post_content' => '',
'post_status' => 'inherit',
);
$filename = $attachment['file'];
$attach_id = wp_insert_attachment($postinfo, $filename, $newId);
if(!function_exists('wp_generate_attachment_data'))
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);
set_post_thumbnail($newId,$attach_id)
它上传图像到介质但不设置为特色的形象,但我认为这个问题是在图片上传,在“媒体”看起来附件屏幕如下
http://cl.ly/image/0z2k1b1d0m1J
这似乎建议一些信息没有通过正确的作为theres没有缩略图,名称或类型。
所有帮助非常感谢! 谢谢
guid在哪里?和$ FILES []数组?并作为sitenote - 为什么不使用download_url()? – krembo99