Postingan lainnya
[HELP] [PHP Native] File Update Process -> Multiple File Upload
Permisi bang atau kak atau om, saya punya form input salah satu masalah nya adalah form ini multiple file upload / lebih dari satu file. Kondisi sekarang saya berhasil membuat form dan file proses input data nya, tapi saya belum bisa membuat proses update data nya. Berikut saya lampirkan script sementara nya.
<?php
include "koneksi.php";
$np = $_POST["produk"];
$dp = $_POST["desk_pro"];
$hrg = $_POST["hrg"];
$mu = $_POST["mu"];
$kt = $_POST["kat"];
$idku = $_POST["id"];
$hd = $_POST["hd"];
$tgl = date("Y:m:d");
// UPLOAD/UPDATE FOTO
$nm_file = $_FILES["fotoku"]["name"];
$str = 'abcdefghijklmnopqrstuvwxyz123456789';
$shuffled = str_shuffle($str);
$data_1 = substr($shuffled , -5);
$data_2 = substr($shuffled , 0,5);
$newname = md5($data_1.$data_2);
$file_name = $newname.$nm_file;
$tmp_file = $_FILES["fotoku"]["tmp_name"];
$sz_file = $_FILES["fotoku"]["size"];
$tp_file = $_FILES["fotoku"]["type"];
$dir = "../hasil-upload/$file_name";
move_uploaded_file($tmp_file, $dir);
// UPLOAD PDF
$nm_file1 = $_FILES["pdf"]["name"];
$str1 = 'abcdefghijklmnopqrstuvwxyz123456789';
$shuffled1 = str_shuffle($str1);
$data_3 = substr($shuffled1 , -5);
$data_4 = substr($shuffled1 , 0,5);
$newname1 = md5($data_3.$data_4);
$file_name1 = $newname1.$nm_file1;
$tmp_file1 = $_FILES["pdf"]["tmp_name"];
$sz_file1 = $_FILES["pdf"]["size"];
$tp_file1 = $_FILES["pdf"]["type"];
$dir1 = "../pdf-folder/$file_name1";
move_uploaded_file($tmp_file1, $dir1);
if ($nm_file == FALSE) {
$sql = "UPDATE tbl_produk
SET nama_produk='$np',
desk_produk='$dp',
harga='$hrg',
mata_uang='$mu',
id_subkat='$kt',
tanggal='$tgl',
headline='$hd'
WHERE id_produk='$idku'";
$query = mysql_query($sql) or die (mysql_error());
} else {
$sql1 = "SELECT * FROM tbl_produk WHERE id_produk='$idku'";
$query1 = mysql_query($sql1) or die(mysql_error());
$data = mysql_fetch_array($query1);
$sql = "UPDATE tbl_produk
SET nama_produk='$np',
desk_produk='$dp',
foto='$file_name',
harga='$hrg',
mata_uang='$mu',
id_subkat='$kt',
tanggal='$tgl',
headline='$hd'
WHERE id_produk='$idku'";
$query = mysql_query($sql) or die (mysql_error());
$path = "../hasil-upload/".$data["foto"];
if (file_exists($path)) {
unlink($path);
}
}
if($query == TRUE){
header("location: tampil-data.php");
} else {
mysql_error();
}
?>
NB: $file_name adalah string nama file foto $file_name1 adalah string nama file pdf
Sementara ini script saya hanya berjalan sampai
move_uploaded_file($tmp_file1, $dir1);
Mohon bantuan nya ya semua :)
0
2 Jawaban:
Promblem Solved
<?php
include "koneksi.php";
$np = $_POST["produk"];
$dp = $_POST["desk_pro"];
$hrg = $_POST["hrg"];
$mu = $_POST["mu"];
$kt = $_POST["kat"];
$idku = $_POST["id"];
$hd = $_POST["hd"];
$tgl = date("Y:m:d");
// UPLOAD/UPDATE FOTO
$nm_file = $_FILES["fotoku"]["name"];
$str = 'abcdefghijklmnopqrstuvwxyz123456789';
$shuffled = str_shuffle($str);
$data_1 = substr($shuffled , -5);
$data_2 = substr($shuffled , 0,5);
$newname = md5($data_1.$data_2);
$file_name = $newname.$nm_file;
$tmp_file = $_FILES["fotoku"]["tmp_name"];
$sz_file = $_FILES["fotoku"]["size"];
$tp_file = $_FILES["fotoku"]["type"];
$dir = "../hasil-upload/$file_name";
move_uploaded_file($tmp_file, $dir);
// UPLOAD PDF
$nm_file1 = $_FILES["pdf"]["name"];
$str1 = 'abcdefghijklmnopqrstuvwxyz123456789';
$shuffled1 = str_shuffle($str1);
$data_3 = substr($shuffled1 , -5);
$data_4 = substr($shuffled1 , 0,5);
$newname1 = md5($data_3.$data_4);
$file_name1 = $newname1.$nm_file1;
$tmp_file1 = $_FILES["pdf"]["tmp_name"];
$sz_file1 = $_FILES["pdf"]["size"];
$tp_file1 = $_FILES["pdf"]["type"];
$dir1 = "../pdf-folder/$file_name1";
move_uploaded_file($tmp_file1, $dir1);
$sql = "UPDATE tbl_produk
SET nama_produk='$np',
desk_produk='$dp',
harga='$hrg',
mata_uang='$mu',
id_subkat='$kt',
tanggal='$tgl',
headline='$hd'
WHERE id_produk='$idku'";
$query = mysql_query($sql) or die (mysql_error());
if ($nm_file == TRUE) {
$sql1 = "SELECT * FROM tbl_produk WHERE id_produk='$idku'";
$query1 = mysql_query($sql1) or die(mysql_error());
$data = mysql_fetch_array($query1);
$sql = "UPDATE tbl_produk
SET foto='$file_name'
WHERE id_produk='$idku'";
$query = mysql_query($sql) or die (mysql_error());
$path = "../hasil-upload/".$data["foto"];
if (file_exists($path)) {
unlink($path);
}
}
if ($nm_file1 == TRUE) {
$sql3 = "SELECT * FROM tbl_produk WHERE id_produk='$idku'";
$query3 = mysql_query($sql3) or die(mysql_error());
$data3 = mysql_fetch_array($query3);
$sql4 = "UPDATE tbl_produk
SET pdf='$file_name1'
WHERE id_produk='$idku'";
$query4 = mysql_query($sql4) or die (mysql_error());
$path1 = "../pdf-folder/".$data3["pdf"];
if (file_exists($path1)) {
unlink($path1);
}
}
if($query == TRUE){
header("location: tampil-data.php");
} else {
mysql_error();
}
?>
0