gpt4 book ai didi

php - Codeigniter无法上传文件

转载 作者:行者123 更新时间:2023-11-29 19:29:39 25 4
gpt4 key购买 nike

我想用结构更新 mysql 上的数据|咬|纳玛 |路径1 |路径2 |

我想更改上传的文件名这是我的 View 代码

<form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/c_main/uploadFile" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputFile">Berkas 1</label>
<input type="hidden" name="nip" id="nipUpload" value="">
<input type="file" class="filestyle" name="berkas[]" data-buttonText="Find file" id="berkas[]">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="form-group">
<label for="exampleInputFile">Berkas 2</label>
<input type="file" class="filestyle" name="berkas[]" data-buttonText="Find file" id="berkas[]">
<p class="help-block">Example block-level help text here.</p>
</div>

<div class="row">
<button type="submit" class="btn btn-default">Upload File</button>
</div>
</form>

this is my controller code

function uploadFile()
{
$nip = $_POST['nip'];

$number_of_files = sizeof($_FILES['berkas']['tmp_name']);

$cek = 0;
for($i=0;$i<$number_of_files;$i++)
{
$namaBerkas[$i] = $nip."-".($i+1).".jpg";

$config['upload_path'] = base_url().'assets/upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$config['max_width'] = 2024;
$config['max_height'] = 1200;
$config['file_name'] = $namaBerkas;

$this->load->library('upload', $config);
// $this->upload->initialize($config);

if ($this->upload->do_upload()){
$cek = $cek +1;
}
print_r($config);
echo $cek;
die();

}

if($cek == 2){
if($this->m_main->uploadFile($nip,$namaBerkas[0],[1])){
echo "<script> alert ('Upload Berkas Berhasi!');</script>";
redirect('admin/C_main/beranda');
}
}

}

这是我的模型

function upload_file($nip, $berkas1, $berkas2){
$sql = "update daftar set PATH1 = $berkas1, PATH2 = $berkas2 WHERE NIP = $nip";
return $this->db2->query($sql);
}

上面代码的输出是:您没有选择要上传的文件。

最佳答案

我认为问题是您有两个相同的表单字段。试试这个

<form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/c_main/uploadFile" enctype="multipart/form-data">
<div class="form-group">
<label for="exampleInputFile">Berkas 1</label>
<input type="hidden" name="nip" id="nipUpload" value="">
<input type="file" class="filestyle" name="berkas[]" data-buttonText="Find file" id="berkas[]">
<p class="help-block">Example block-level help text here.</p>
</div>
<div class="row">
<button type="submit" class="btn btn-default">Upload File</button>
</div>
</form>

关于php - Codeigniter无法上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41888459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com