9

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.

2 Answers 2

29

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" />
Sign up to request clarification or add additional context in comments.

2 Comments

It did. I dived into the code in that plugin and found my answer. Thanks.
I'd prefer to write out the code that helped me and accept that as the answer, but I'll upvote your answer for helping me out.
8

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

3 Comments

How is this different from the answer mnelson7982 posted?
It's not. He just wanted the solve checkmark for himself.
Code in answer from @mnelson7982 was added about 4 months later... Original answer just had a link to WPTuts page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.