我想使用输入type =“ file”上传任何尺寸的图像。我目前正在尝试上传2-3 MB的图像,但是它不起作用,并且其他表单数据也没有显示在数据库中。
我目前在表单中使用此代码上传图片:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
<div class="col-md-3 col-lg-3 col-xs-12 col-sm-12 upload2">
<img id="file1" width="150" height="80">
<input type="file" name="a_image[]" required id="imgupload" style="display:none" onChange="document.getElementById('file1').src = window.URL.createObjectURL(this.files[0])">
<br>
<a href="#" class="upload" onclick="$('#imgupload').trigger('click'); return false;"> <i class="fa fa-upload" aria-hidden="true"></i> Upload </a>
</div>
<div class="col-md-3 col-lg-3 col-xs-12 col-sm-12 upload2">
<img id="file2" width="150" height="80">
<input type="file" name="a_image[]" id="imgupload1" style="display:none" onChange="document.getElementById('file2').src = window.URL.createObjectURL(this.files[0])">
<br>
<a href="#" class="upload" onclick="$('#imgupload1').trigger('click'); return false;"><i class="fa fa-upload" aria-hidden="true"></i> Upload </a>
</div>
<div class="col-md-3 col-lg-3 col-xs-12 col-sm-12 upload2">
<img id="file3" width="150" height="80">
<input type="file" name="a_image[]" id="imgupload2" style="display:none" onChange="document.getElementById('file3').src = window.URL.createObjectURL(this.files[0])">
<br>
<a href="#" class="upload" onclick="$('#imgupload2').trigger('click'); return false;"><i class="fa fa-upload" aria-hidden="true"></i> Upload </a>
</div>
<div class="col-md-3 col-lg-3 col-xs-12 col-sm-12 upload2">
<img id="file4" width="150" height="80">
<input type="file" name="a_image[]" id="imgupload3" style="display:none" onChange="document.getElementById('file4').src = window.URL.createObjectURL(this.files[0])">
<br>
<a href="#" class="upload" onclick="$('#imgupload3').trigger('click'); return false;"><i class="fa fa-upload" aria-hidden="true"></i> Upload </a>
</div>
</div>
在模型页面上
$id = $a_id;
$i = 0;
foreach($_FILES['a_image']['tmp_name'] as $key => $tmp_name)
{
$i++;
$file_tmp =$_FILES['a_image']['tmp_name'][$key];
move_uploaded_file($file_tmp,"template/uploads/product/ad_".$id."_".$i.'.jpg');
$source_path = "template/uploads/product/ad_".$id."_".$i.".jpg";
$thumb_path = 'template/uploads/product/thumb/ad_'.$id.'_'.$i.'.jpg';
$this->upload_thumbnail($source_path,$thumb_path,'200','200');
}
答案 0 :(得分:1)
我相信输入类型文件的默认最大大小为 20 MB 。
要更改此...
如果创建具有类似值的.htaccess
,则将以下代码添加到php.ini
中。
php_value post_max_size 100M
php_value upload_max_filesize 100M
php_value memory_limit 64M
它可能不起作用,但还是请尝试一下!
答案 1 :(得分:0)
通过设置以下内容来限制php.ini中的这些内容:
`upload_max_filesize = 4M` `post_max_size = 8M`