我正在尝试使用以下代码限制上传图片大小:
<input type="file" class="upload" name="image" value="<?php echo set_value('image'); ?>" /> <!--<button id='submit_btn' class="btn btn-default">upload</button> -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).on('change','.upload',function(){
files = this.files;
size = files[0].size;
//max size 50kb => 50*1000
if( size > 1000141){
alert('Please upload less than 1mb file');
return false;
}
return true;
});
</script>
当我上传大于1 mb的图片时,上传成功完成。这个问题是什么? Bt图像没有上传到数据库中的文件夹
答案 0 :(得分:0)
文件大小使用jquery验证(onsubmit验证)试试这段代码,你会得到结果。
<form action="<?=site_url('search/do_register')?>" method="post" enctype="multipart/form-data" onSubmit="return function();">
<input type="file" class="upload" name="image" value="<?php echo set_value('image'); ?>"/>
<input type="submit" name="btn-reg" value=" Register " />
<script type="text/javascript">
$(document).on('change','.upload',function(){
files = this.files;
size = files[0].size;
//max size 50kb => 50*1000
if( size > 1000141){
alert('Please upload less than 1mb file');
return false;
}
return true;
});
</script>