How do I upload a file to wordpress using a custom upload form?

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.

Answers


Does this help?

WPTuts: Allow users to submit images to your site

PHP:

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);

HTML:

<input type="file" name="file-upload" id="file-upload" />

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" />

Need Your Help

How do you convert YYYY-MM-DDTHH:mm:ss.000Z time format to MM/DD/YYYY time format in Python?

python datetime

For example, I'm trying to convert 2008-09-26T01:51:42.000Z to 09/26/2008. What's the simplest way of accomplishing this?

Eclipse auto suggest list very slow

eclipse autosuggest

By auto suggest, I mean that intellisense that pops up when I write something. My problem is that if I write something like btnMyButton. after typing . I get to wait a few seconds until eclipse