Wordpress中的前端媒体上传 [英] Front End Media Uploading in Wordpress

查看:146
本文介绍了Wordpress中的前端媒体上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助! :)

I'm in need of some help! :)

我要做的是让用户从前端创建一个帖子。使用预览窗口显示发布时帖子的外观。我已经完成了。现在我试图让用户将图像直接上传到媒体库。一旦用户选择了包含以下代码的文件,就需要进行此上传:

What I'm trying to do is let a user create a post from the front end. With a preview window of how the post will look like when published. This I have already accomplished. Now I'm trying to allow the user to upload a image directly into the media library. This upload needs to happen as soon as the user has chosen the file with the follow code:

 <form method="post" action="#" enctype="multipart/form-data" >
      <input type="file" name="featured_image">
 </form>

我不希望任何页面加载,有没有办法在不使用提交的情况下获取文件按钮?
另外我如何处理实际的文件上传,我的谷歌技能发现了这个功能:

I don't want any page load, is there a way to get the file without using a submit button? Also how do I handle the actual file upload, my google skills found this function:

function insert_attachment($file_handler,$post_id,$setthumb='false') {

  // check to make sure its a successful upload
  if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();

  require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  require_once(ABSPATH . "wp-admin" . '/includes/media.php');

  $attach_id = media_handle_upload( $file_handler, $post_id );

  if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
 return $attach_id;
}

但是这个函数将上传挂钩到帖子,我只是想让它去直接进入图书馆而没有连接到帖子。另外我假设$ file_handler是表单的名称?我还假设$ _FILES不存在,除非用户点击了一个提交按钮。

But this function hooks the upload to a post, I just want it to go straight into the library without being connected to a post. Also I assume the $file_handler is the name of the form? I also assume that $_FILES doesn't exists unless the user has clicked a submit button.

我在这里离我很吵,谈论我的屁股。所以任何帮助都会受到关注。有没有可用的WP-gurus? :D

I'm prolly way off here, talking out of my ass. So any help would be appriciated. Any WP-gurus available? :D

推荐答案

好的,我正在向前迈进。我现在使用这个jquery插件进行图片上传 - >
http://lagoscript.org/jquery/上传

Ok, I'm getting forward. I'm now using this jquery plugin for image uploading -> http://lagoscript.org/jquery/upload

这是非常轻量级的,效果很好。将图像上传到我的电脑而不刷新。它将文件保存在我的服务器上的临时目录中,我现在打算以某种方式将此图像注入媒体库(然后将其从临时文件夹中删除),但这似乎比它应该更难。

Which is very lightweight and works great. Uploads the image to my computer without refreshing. It saves the file in a temp dir on my server, what I'm planning to do now is somehow inject this image into the media library (and then delete it from the temp folder), but this seems harder than it should.

有没有什么方法可以使用php-code将图像添加到媒体库,只使用图片网址?
我似乎无法找到一个,但由于WP已在管理区域中具有此功能,因此必须有一种方法。

Is there any way I can add a image to the media library with php-code, using only a image url? I can't seem to find one, but since WP has this feature in the admin-area already there must be a way.

最简单的方法似乎只是创建一个自定义字段来存储该帖子的图像,但我真的希望能够使用WPs缩略图功能,而不仅仅是循环,但用于调整大小等。

The easiest way seems to be just creating a custom field that stores the image for that post, but I really want to be able to use WPs thumbnail functions, not only for looping, but for resizing etc.

任何指针?

这篇关于Wordpress中的前端媒体上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆