【问题标题】:How to allow users to upload images on Wordpress?如何允许用户在 Wordpress 上上传图片?
【发布时间】:2011-06-05 12:34:35
【问题描述】:

我正在开发一个 Wordpress 网站,允许(注册)用户将图片和描述上传到画廊,但我不确定这样做的最佳方式。

我不希望他们通过网站的后端进行操作,而是通过网站上的“您的项目”页面和表单来完成。该表单将包含一些文本字段和文件上传区域。

我正在考虑尝试调整 Contact Form 7 来处理此问题,但不确定是否可行。

是否有任何插件可以做到这一点?谢谢

【问题讨论】:

标签: php wordpress upload


【解决方案1】:

您最好的选择是创建一个自定义插件来执行此操作,例如:

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

【讨论】:

    【解决方案2】:

    我发现这个插件几乎完全符合我的要求 - 而且你可以为每张图片投票。 自定义非常好,如果你在代码中乱七八糟,你可以做更多。希望这可以帮助其他寻找此功能的人。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2017-05-21
      • 2017-12-06
      相关资源
      最近更新 更多