我想用结构更新我的mysql数据 |咬合| nama | path1 | path2 |
我想通过上传的文件名进行更改 这是我的观点代码
<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);
}
上面代码的输出是:您没有选择要上传的文件。
答案 0 :(得分:0)
我认为问题是你有两个相同的表单字段。试试这个
<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>
答案 1 :(得分:0)
<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="berkas1" data-buttonText="Find file" id="berkas1">
<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>
<强> Conrtoller 强>
function uploadFile()
{
$nip = $_POST['nip'];
$number_of_files = sizeof($_FILES['berkas']['tmp_name']);
$cek = 0;
$namaBerkas = $nip."-".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('berkas')){
$cek = $cek +1;
}
$namaBerkas1 = $nip."-".2.".jpg";
$config['file_name'] = $namaBerkas1;
if ($this->upload->do_upload('berkas1')){
$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');
}
}
}