Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 417
jasonaburton Avatar asked Jan 19 '12 19:01

jasonaburton


People also ask

How do I upload a custom file in WordPress?

On the Dashboard menu, click Posts, and then click Add New to display the "Add New Post" page. On the Upload/Insert menu, click the icon for the type of file you want to upload and the "Add media files from your computer" page will appear. Click the Select Files button.

Can I upload a document to WordPress?

The following process describes uploading a document from your computer to your site's Media Library and inserting a download link into a post or page. Go to My Site(s) → Media. Choose a file (or multiple files) from your computer to upload. Once the file has finished uploading, click the Edit button.


2 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" />
like image 165
mnelson7982 Avatar answered Sep 23 '22 13:09

mnelson7982


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" />
like image 31
jasonaburton Avatar answered Sep 19 '22 13:09

jasonaburton