public function ubahLampiran() { $id_lamp = $_POST['id']; $id_surat = $_POST['id_surat']; $tgl = $_POST['tanggal']; $jns = $_POST['jenis']; $tipe = $_POST['tipe']; $nomor = $_POST['nomor']; $asal = $_POST['asal']; $hal = $_POST['hal']; $ket = $_POST['keterangan']; //nama baru akan terdiri dari tipe naskah_nomor surat_asal(asal/tetapi asal terlaku kepanjangan) if ($_FILES['upload']['name'] != '') { $upload = new Upload('upload'); $upload->setDirTo('arsip/'); $ubahNama = array($tipe, $nomor); $upload->setUbahNama($ubahNama); $upload->changeFileName($upload->getFileName(), $ubahNama); $namafile = $upload->getFileTo(); } else { $filex = $_POST['file']; $file = explode("_", $filex); $j = count($file); $ext = explode('.', $file[$j - 1]); // var_dump($ext); // var_dump($file); // $namafile = explode("_", $file); // var_dump($namafile); $file[0] = $tipe; $namafile = ''; for ($i = 0; $i < $j - 1; $i++) { $namafile .= '_' . $file[$i]; echo $file[$i] . '</br>'; } $namafile = trim($namafile, "_") . '_' . $ext[0] . '.' . $ext[1]; // var_dump($namafile); // $namafile = implode("_", $namafile); rename('arsip/' . $filex, 'arsip/' . $namafile); } //$upload->init('upload'); $lamp = new Lampiran_Model(); $lamp->set('id_lamp', $id_lamp); $lamp->set('jns_surat', $jns); $lamp->set('id_surat', $id_surat); $lamp->set('tipe', $tipe); $lamp->set('nomor', $nomor); $lamp->set('tanggal', $tgl); $lamp->set('asal', $asal); $lamp->set('hal', $hal); $lamp->set('keterangan', $ket); $lamp->set('file', $namafile); /*$data = array( 'jns_surat'=>$jns, 'id_surat'=>$_POST['id'], 'tipe'=>$tipe, 'nomor'=>$nomor, 'tanggal'=> Tanggal::ubahFormatTanggal($_POST['tanggal']), 'hal'=>$_POST['hal'], 'asal'=>$asal, 'keterangan'=>$_POST['keterangan'], 'file'=>$namafile//upload belom diurus );*/ //var_dump($data); if ($lamp->editLampiran()) { if ($_FILES['upload']['name'] != '') { $upload->uploadFile(); } echo "<div id=success>Ubah data lampiran berhasil</div>"; } else { echo "<div id=error>Ubah data lampiran gagal!</div>"; } /*if($jns=='SM'){ header('location:'.URL.'suratmasuk/detil/'.$data['id_surat']); }elseif ($jns=='SK') { header('location:'.URL.'suratkeluar/detil/'.$data['id_surat']); }*/ // return true; }