在前端提交表单中限制最大上载文件大小

时间:2017-07-20 作者:webrex

我是WordPress的初学者,我正在开发一个旅行目录,用户可以注册该目录,并有一个前端控制面板和一个前端提交表单,用户可以在其中添加属性描述,当然还有图像。

我有一个多站点安装,但上载设置不适用于前端(最大上载文件大小和文件类型)。我想我可以使用过滤器,但我找不到适用于前端的东西。。。尝试了几个插件,都在后端工作。

事实上,我需要一个循序渐进的帮助或在线指南,我还没有找到。

谢谢

2 个回复
SO网友:Cesar Henrique Damascena

您有一些方法可以做到这一点:

在您的functions.phpwp-config.php

@ini_set( \'upload_max_size\' , \'15M\' );
@ini_set( \'post_max_size\', \'15M\');
@ini_set( \'max_execution_time\', \'300\' );
在您的.htaccess (如果使用apache2)

php_value upload_max_filesize 15M
php_value post_max_size 15M
php_value max_execution_time 300
php_value max_input_time 300
如果您使用nginx

http {
  client_max_body_size 15m;
}
在您的php.ini

upload_max_filesize = 15M
post_max_size = 15M
max_execution_time = 300
它们都能工作,所以你可以选择最适合你的,大小以MB为单位,所以上面的所有示例都会将最大上载设置为15MB.

SO网友:webrex
<?php
global $action;
global $edit_id;
global $embed_video_id;
global $option_video;
global $edit_link_details;
$images=\'\';
$thumbid=\'\';
$attachid=\'\';
$arguments = array(
  \'numberposts\'     => -1,
  \'post_type\'       => \'attachment\',
  \'post_parent\'     => $edit_id,
  \'post_status\'     => null,
  \'exclude\'         => get_post_thumbnail_id(),
  \'orderby\'         => \'menu_order\',
  \'order\'           => \'ASC\'
 );
 $post_attachments = get_posts($arguments);
 $post_thumbnail_id = $thumbid = get_post_thumbnail_id( $edit_id );


foreach ($post_attachments as $attachment) {
    $preview =  wp_get_attachment_image_src($attachment->ID,                    \'wpestate_property_listings\');    

    if($preview[0]!=\'\'){
        $images .=  \'<div class="uploaded_images"                                      data-imageid="\'.$attachment->ID.\'"><img src="\'.$preview[0].\'" alt="thumb"          /><i class="fa fa-trash-o"></i>\';
        if($post_thumbnail_id == $attachment->ID){
            $images .=\'<i class="fa thumber fa-star"></i>\';
        }
    }else{
        $images .=  \'<div class="uploaded_images" data-imageid="\'.$attachment->ID.\'"><img src="\'.get_template_directory_uri().\'/img/pdf.png" alt="thumb" /><i class="fa fa-trash-o"></i>\';
        if($post_thumbnail_id == $attachment->ID){
            $images .=\'<i class="fa thumber fa-star"></i>\';
        }
    }


    $images .=\'</div>\';
    $attachid.= \',\'.$attachment->ID;
    }


   ?>


<div class="col-md-12" id="new_post2">
<div class="user_dashboard_panel">
<h4 class="user_dashboard_panel_title"><?php  esc_html_e(\'Listing           Media\',\'wpestate\');?></h4>



<div class="col-md-12" id="profile_message"></div>

<div class="col-md-12">
    <div id="upload-container">                 
        <div id="aaiu-upload-container">                 
            <div id="aaiu-upload-imagelist">
                <ul id="aaiu-ul-list" class="aaiu-upload-list"></ul>
            </div>

            <div id="imagelist">
            <?php 
                if($images!=\'\'){
                    print $images;
                }
            ?>  
            </div>

            <div id="aaiu-uploader"  class=" wpb_btn-small wpestate_vc_button  vc_button"><?php esc_html_e(\'Select Media\',\'wpestate\');?></div>
            <input type="hidden" name="attachid" id="attachid" value="<?php echo $attachid;?>">
            <input type="hidden" name="attachthumb" id="attachthumb" value="<?php echo $thumbid;?>">
            <p class="full_form full_form_image">
                <?php esc_html_e(\'*Double Click on the image to select featured. \',\'wpestate\');?></br>
                 <?php esc_html_e(\'**Change images order with Drag & Drop. \',\'wpestate\');?>
            </p>
        </div>  
    </div>
</div>

<div class="col-md-4">
    <p>
        <label for="embed_video_type"><?php esc_html_e(\'Video from\',\'wpestate\');?></label>
        <select id="embed_video_type" name="embed_video_type" class="select-submit2">
            <?php print $option_video;?>
        </select>
    </p>
</div>


<div class="col-md-4">
    <p>     
       <label for="embed_video_id"><?php esc_html_e(\'Video id: \',\'wpestate\');?></label>
       <input type="text" id="embed_video_id" class="form-control"  name="embed_video_id" size="40" value="<?php print $embed_video_id;?>">
    </p>
</div>

 <div class="col-md-12" style="display: inline-block;"> 
    <input type="hidden" name="" id="listing_edit" value="<?php echo  $edit_id;?>">
    <input type="submit" class="wpb_btn-info wpb_btn-small wpestate_vc_button  vc_button" id="edit_prop_image" value="<?php esc_html_e(\'Save\', \'wpestate\') ?>" />
    <a href="<?php echo  $edit_link_details;?>" class="next_submit_page"><?php esc_html_e(\'Go to Details settings (*make sure you click save first).\',\'wpestate\');?></a>

 </div>

 </div>  
结束

相关推荐

将WordPress附件导入wp-Content/Uploads/中的自定义目录

我希望有人能阐明我试图解决的这个问题,即使只是简单地改变我的思维过程,告诉我如何解决这个问题。我正在将一个基于CakePHP的定制CMS web应用程序导入WordPress,方法是遍历数据库,进行大量SQL查询,构建数组,最后输出必要的XML文件,以便使用WordPress导入工具导入。目前我已经很好地导入了类别、标签和帖子/页面,没有问题,但问题似乎出在图像上。基于CakePHP的CMS中当前的图像格式是images/year/month/day/post_id/image_name.ext据我所知,