我想更新我的數據在mysql的結構 | nip |納馬| 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);
}
上面的代碼的輸出是:你沒有選擇要上傳的文件。
初始化上傳。刪除// $ $ this-> upload-> initialize($ config); – Ritchie
已經嘗試過,但仍然得到了相同的輸出結果「您沒有選擇要上傳的文件」。 @Ritchie –
查詢打印什麼? –