首页 > 解决方案 > 输入类型=文件不能接受大尺寸图片

问题描述

我想使用输入类型=“文件”上传任何大小的图像。我目前正在尝试上传 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');
    }

标签: phphtml

解决方案


我相信输入类型文件的默认最大大小是20 兆字节

要改变这个...

.htaccess如果创建php.ini具有相似值的代码,请将以下代码添加到您的代码中。

 php_value post_max_size 100M
 php_value upload_max_filesize 100M
 php_value memory_limit 64M

它可能不起作用,但无论如何都要尝试一下!


推荐阅读