คือต้องการคำสั่งที่ชนิดไฟล์มันไม่ตรงกับที่กำหนดจะเก็บในฐานข้อมูลไม่ได้ค่ะ คำสั่งที่เราทำมันไม่ตรงมันก็เก็บข้อมูลอันอื่นไว้ในฐานอยู่ดี
พอมีใครช่วยได้บ้างมั้ยคะ
Full Codeค่ะ
<?php
require_once "../config.php";
if (isset($_POST['submit']))
{
//get value from clientd.php
$pname = $_POST['npemohon'];
$notel1 = $_POST['notel1'];
$notel2 = $_POST['notel2'];
$noic = $_POST['noic'];
$fnoic = $_FILES['fnoic']['name']; //UPLOAD FILE
$npemilih = $_POST['npemilih'];
$fgeran = $_FILES['fsgeran']['name']; //UPLOAD FILE
$jtanah = implode(' ',$_POST['jtnh']); //utk radio,checkbox, select item
$hubungan = $_POST['hubungan'];
$lokasi = $_POST['lksi'];
$jpembiayaan = $_POST['jpby'];
$hjual = $_POST['hjual'];
$hkps = $_POST['hkps'];
$keluasan = $_POST['kluas'];
$hkon = $_POST['hkon'];
$hpnambahan = $_POST['hpnamb'];
$narkitek1 = $_POST['nartk1'];
$narkitek2 = $_POST['nartk2'];
$arkitekfee = $_POST['arktfee'];
$nlawyer = $_POST['nlaw'];
$feelawyer = $_POST['lawyerf'];
$dbooking = $_POST['dbooking'];
//allowed file type
$extic = pathinfo($fnoic, PATHINFO_EXTENSION);
$extgeran = pathinfo($fgeran, PATHINFO_EXTENSION);
$allowed = ['pdf', 'txt', 'doc', 'docx', 'png', 'jpg', 'jpeg', 'gif', 'excel', 'mp4', 'xls','png'];
//check if file type is valid for file noic
if (in_array($extic, $allowed))
{
// get last record id
$sql = 'select max(id) as id from clientdata';
$query_sql = mysqli_query($link, $sql);
if (count($query_sql) > 0)
{
$row = mysqli_fetch_array($query_sql);
$fnoic = ($row['id']+1) . '-' . $fnoic;
}
else
$fnoic = '1' . '-' . $fnoic;
//set target directory
$path1 = 'uploadic/';
if (!is_dir($path1)) {
echo 'error';
} else {
//Save the uploaded file from the database in the created folder.
move_uploaded_file($_FILES['fnoic']['tmp_name'],($path1 . $fnoic));
}
}
else
{
//Display when the file type does not match the specified file type.
//echo mysqli_connect_error($link);
echo'<script>alert("File No. IC cannot be saved (This file type is not allowed.)")</script>';
}
//--------------------------------------------------------------------------
//check if file type is valid for file salinan geran
if (in_array($extgeran, $allowed))
{
// get last record id
$sql = 'select max(id) as id from clientdata';
$query_sql = mysqli_query($link, $sql);
if (count($query_sql) > 0)
{
$row = mysqli_fetch_array($query_sql);
$fgeran = ($row['id']+1) . '-' . $fgeran;
}
else
$fgeran = '1' . '-' . $fgeran;
//set target directory
$path2 = 'uploadgeran/';
if (!is_dir($path2)) {
echo 'error';
} else {
//Save the uploaded file from the database in the created folder.
move_uploaded_file($_FILES['fsgeran']['tmp_name'],($path2 . $fgeran));
}
}
else
{
//Display when the file type does not match the specified file type.
//echo mysqli_connect_error($link);
echo'<script>alert("Grant Copy Files cannot be saved (This type of file is not allowed.)")</script>';
}
// insert file details into database
$sql = "INSERT INTO clientdata(id,nama,notel1,notel2,noic,snoic,nmapemilih,sgran,jtanah,hubungan,lokasi,
jpembiayaan,hjualan,hkaki,keluasan,hkontrak,hpnambah,narkitak1,narkitak2,arkitekfee,nlawyer,lawyerfee,dbooking)
VALUES (NULL,'".$pname."','".$notel1."','".$notel2."','".$noic."','".$fnoic."','".$npemilih."',
'".$fgeran."','".$jtanah."','".$hubungan."','".$lokasi."','".$jpembiayaan."','".$hjual."','".$hkps."',
'".$keluasan."','".$hkon."','".$hpnambahan."','".$narkitek1."','".$narkitek2."','".$arkitekfee."','".$nlawyer."',
'".$feelawyer."','".$dbooking."')";
$query_sql=mysqli_query($link,$sql);
//noti after submit and go to main page
echo "<script>
window.location.href='clientd.php';
alert('Your information has been saved. Thank you');
</script>";
}else{
echo "<script>
window.location.href='clientd.php';
alert('Value is not available');
</script>";
}
?>
อยากสร้างคำสั่งที่ถ้าชนิดไฟล์ไม่ตรงตามที่กำหนดไปไม่สามารถเก็บไว็ในdatabasewได้ ทำยังไงได้บ้าง?
พอมีใครช่วยได้บ้างมั้ยคะ
Full Codeค่ะ
<?php
require_once "../config.php";
if (isset($_POST['submit']))
{
//get value from clientd.php
$pname = $_POST['npemohon'];
$notel1 = $_POST['notel1'];
$notel2 = $_POST['notel2'];
$noic = $_POST['noic'];
$fnoic = $_FILES['fnoic']['name']; //UPLOAD FILE
$npemilih = $_POST['npemilih'];
$fgeran = $_FILES['fsgeran']['name']; //UPLOAD FILE
$jtanah = implode(' ',$_POST['jtnh']); //utk radio,checkbox, select item
$hubungan = $_POST['hubungan'];
$lokasi = $_POST['lksi'];
$jpembiayaan = $_POST['jpby'];
$hjual = $_POST['hjual'];
$hkps = $_POST['hkps'];
$keluasan = $_POST['kluas'];
$hkon = $_POST['hkon'];
$hpnambahan = $_POST['hpnamb'];
$narkitek1 = $_POST['nartk1'];
$narkitek2 = $_POST['nartk2'];
$arkitekfee = $_POST['arktfee'];
$nlawyer = $_POST['nlaw'];
$feelawyer = $_POST['lawyerf'];
$dbooking = $_POST['dbooking'];
//allowed file type
$extic = pathinfo($fnoic, PATHINFO_EXTENSION);
$extgeran = pathinfo($fgeran, PATHINFO_EXTENSION);
$allowed = ['pdf', 'txt', 'doc', 'docx', 'png', 'jpg', 'jpeg', 'gif', 'excel', 'mp4', 'xls','png'];
//check if file type is valid for file noic
if (in_array($extic, $allowed))
{
// get last record id
$sql = 'select max(id) as id from clientdata';
$query_sql = mysqli_query($link, $sql);
if (count($query_sql) > 0)
{
$row = mysqli_fetch_array($query_sql);
$fnoic = ($row['id']+1) . '-' . $fnoic;
}
else
$fnoic = '1' . '-' . $fnoic;
//set target directory
$path1 = 'uploadic/';
if (!is_dir($path1)) {
echo 'error';
} else {
//Save the uploaded file from the database in the created folder.
move_uploaded_file($_FILES['fnoic']['tmp_name'],($path1 . $fnoic));
}
}
else
{
//Display when the file type does not match the specified file type.
//echo mysqli_connect_error($link);
echo'<script>alert("File No. IC cannot be saved (This file type is not allowed.)")</script>';
}
//--------------------------------------------------------------------------
//check if file type is valid for file salinan geran
if (in_array($extgeran, $allowed))
{
// get last record id
$sql = 'select max(id) as id from clientdata';
$query_sql = mysqli_query($link, $sql);
if (count($query_sql) > 0)
{
$row = mysqli_fetch_array($query_sql);
$fgeran = ($row['id']+1) . '-' . $fgeran;
}
else
$fgeran = '1' . '-' . $fgeran;
//set target directory
$path2 = 'uploadgeran/';
if (!is_dir($path2)) {
echo 'error';
} else {
//Save the uploaded file from the database in the created folder.
move_uploaded_file($_FILES['fsgeran']['tmp_name'],($path2 . $fgeran));
}
}
else
{
//Display when the file type does not match the specified file type.
//echo mysqli_connect_error($link);
echo'<script>alert("Grant Copy Files cannot be saved (This type of file is not allowed.)")</script>';
}
// insert file details into database
$sql = "INSERT INTO clientdata(id,nama,notel1,notel2,noic,snoic,nmapemilih,sgran,jtanah,hubungan,lokasi,
jpembiayaan,hjualan,hkaki,keluasan,hkontrak,hpnambah,narkitak1,narkitak2,arkitekfee,nlawyer,lawyerfee,dbooking)
VALUES (NULL,'".$pname."','".$notel1."','".$notel2."','".$noic."','".$fnoic."','".$npemilih."',
'".$fgeran."','".$jtanah."','".$hubungan."','".$lokasi."','".$jpembiayaan."','".$hjual."','".$hkps."',
'".$keluasan."','".$hkon."','".$hpnambahan."','".$narkitek1."','".$narkitek2."','".$arkitekfee."','".$nlawyer."',
'".$feelawyer."','".$dbooking."')";
$query_sql=mysqli_query($link,$sql);
//noti after submit and go to main page
echo "<script>
window.location.href='clientd.php';
alert('Your information has been saved. Thank you');
</script>";
}else{
echo "<script>
window.location.href='clientd.php';
alert('Value is not available');
</script>";
}
?>