2013-03-24 02:04 阅读 41


Trying to make a form to upload an image to Wordpress, then set that image as a post's thumbnail. But I can't seem to get the media_handle_upload() function to work properly.

the form's input for the file

 <input type="file" name="image" />

then this is the server side code

media_handle_upload( $_FILES['image'], 22 );

and this is what I get returned

object(WP_Error)#212 (2) { ["errors"]=> array(1) { ["upload_error"]=> array(1) { [0]=> string(212) "File is empty...." } } ["error_data"]=> array(0) { } }

I have played around with a couple different ways to enter the file variable,but none seems to work, am I doing that from, what exactly is the $file_id;

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dshakcsq64956 dshakcsq64956 2013-03-24 04:53

    Looking at documentation for media_handle_upload(), the first parameter should be the name of the index for the file in the $_FILES array, so in your case it should look like this:

    media_handle_upload('image', 22);
    点赞 评论 复制链接分享