如何使用自定义上传表单将文件上传到wordpress? [英] How do I upload a file to wordpress using a custom upload form?
本文介绍了如何使用自定义上传表单将文件上传到wordpress?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网站上有一个表单(位于前端),我需要允许任何人将图片上传到我在wp-content中的上传文件夹中。我找到了很多教程,但是他们都告诉我如何使用wordpress上传器。我需要能够验证用户正在上传。
任何帮助,非常感谢!!!
谢谢。
解决方案
解决了。这是我用来做的代码:
在我的代码中:
require_once(ABSPATH。wp-admin。'/includes/image.php');
require_once(ABSPATH。wp-admin。'/includes/file.php');
require_once(ABSPATH。wp-admin。'/includes/media.php');
$ attachment_id = media_handle_upload('file-upload',$ post-> ID);
在我的表单中:
< input type =filename =file-uploadid =file-upload/>
I don't want to use Wordpress' built in media uploader.
I have a form (on the frontend) of my site, and I need to allow anyone to upload an image to my uploads folder in wp-content. I've found many tutorials, but they all tell me how to do it with the wordpress uploader. I need to be able to validate what users are uploading.
Any help is greatly appreciated!!!
Thanks.
解决方案
Solved. This is the code I used to do it:
In my code:
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attachment_id = media_handle_upload('file-upload', $post->ID);
In my form:
<input type="file" name="file-upload" id="file-upload" />
这篇关于如何使用自定义上传表单将文件上传到wordpress?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文