开发者

How to allow users to upload images on Wordpress?

I'm developing a Wordpress site that will let (registered) users upload an image and description to a gallery, but am not sure the best way to do so.

I d开发者_StackOverflowo not want them to do it through the back end of the site, but rather a "Your Projects" page on the site with a form. The form will have a few text fields and the file upload area.

I was thinking of trying to adapt Contact Form 7 to handle this, but not sure if it's even possible.

Are there any plugins out there that would do this? Thanks


Your best bet is to create a custom plugin to do it with something like:

$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
   'post_mime_type' => $wp_filetype['type'],
   'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
   'post_content' => '',
   'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, 37 );
// you must first include the image.php file
// for the function wp_generate_attachment_metadata() to work
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id,  $attach_data );


I found this plugin that does pretty much exactly what I want - plus you can vote for each image. Customization is pretty good, and if you mess around in the code you can do more. Hope this helps anyone else looking for this functionality.

http://wordpress.org/extend/plugins/photosmash-galleries/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜