|
 |
|
รบกวนช่วยดูเกี่ยวกับการ Upload image ให้หน่อยครับ ติดปัญหาตรงที่มันไม่ดึงนามสกุลfile ให้ครับ |
|
 |
|
|
 |
 |
|
ตามหัวข้อเลยครับ ติดปัญหาตรงที่มันไม่ดึงนามสกุลของfileน่ะครับ
Code (PHP)
$emp_name = $_POST['emp_name'];
$emp_surname = $_POST['emp_surname'];
$emp_password = $_POST['emp_password'];
$emp_email = $_POST['emp_email'];
$emp_number = $_POST['emp_number'];
$emp_address = $_POST['emp_address'];
$emp_district = $_POST['emp_district'];
$emp_prefecture = $_POST['emp_prefecture'];
$emp_province = $_POST['emp_province'];
$emp_id_card = $_POST['emp_id_card'];
$emp_status = $_POST['emp_status'];
$emp_hash = md5($emp_password);
$sql = "SELECT * FROM employee WHERE emp_email = '$emp_email' ";
$result = mysqli_query($con, $sql);
$num_row = mysqli_num_rows($result);
if ($num_row == 1) {
echo "<script>alert('Email มีอยู่แล้ว กรุณาเลือกชื่ออื่น');window.location='Add_Emp.php';</script>";
} else if (checkPassword($emp_password) == false) {
echo "<script>alert('!ผิดพลาด รหัสผ่านต้องมีทั้งอักษรและตัวเลข และยาวอย่างน้อย 8 ตัวอักษร');window.location='Add_Emp.php';</script>";
//ตรวจสอบว่าอีเมลถูกต้องหรือไม่
} else if (checkEmail($emp_email) == false) {
echo "<script>alert('!ผิดพลาด คุณกรอกอีเมล์ไม่ถูกต้อง');window.location='Add_Emp.php';</script>";
//ตรวจสอบว่าเบอร์โทรศัพท์ถูกต้องหรือไม่
} else if (checkNumber($emp_number) == false && $emp_number != '') {
echo "<script>alert('!ผิดพลาด คุณกรอกเบอร์โทรศัพท์ไม่ถูกต้อง');window.location='Add_Emp.php';</script>";
//ตรวจสอบว่ารหัสไปรษณีย์ถูกต้องหรือไม่
} else if (checkIdcard($emp_id_card) == false && $emp_id_card != '') {
echo "<script>alert('!ผิดพลาด คุณกรอกรหัสบัตรประชาชนไม่ถูกต้อง');window.location='Add_Emp.php';</script>";
} else {
//upload image
$img = pathinfo(basename($_FILES['emp_image']['name']), PATHINFO_EXTENSION); //ให้ทำการดึงนามสกุลที่มาจากfileที่ผู้ใช้uploadเข้ามา
$new_imgage_name = 'img_' . uniqid() . "." . $img;
//ให้ข้นต้นด้วย เเล้วทำการสุ่มชื่อfileใหม่เพื่อให้ได้ชื่อที่ไม่ซ้ำกัน เเล้วตามด้วยนามสกุลfile
$image_path = "image/"; //กำหนดว่าfileอยู่ตรงไหน
$upload_path = $image_path . $new_imgage_name; //จะได้ว่า image/ตามด้วยชื่อfileใหม่
//เริ่มupload
$success = move_uploaded_file($_FILES['emp_image']['tmp_name'], $upload_path);
//เป็นชื่อกล่องที่ผู้ใช้ upload
if ($success == FALSE) {
echo "<script>alert('ไม่สามารถ upload รูปภาพได้');window.location='Add_Emp.php';</script>";
}
// เพิ่มชื่อรูปภาพใหม่เข้าไปในdatabase
$emp_image = $new_imgage_name; // เอาชื่อรูปภาพใหม่เข้ามาไว้ใน $emp_image
$sql = "INSERT INTO employee (emp_name, emp_surname, emp_password,emp_email,emp_number,emp_address,emp_district,emp_prefecture,emp_province,emp_id_card,emp_image,emp_status ) "
. "VALUES ('$emp_name','$emp_surname','$emp_hash','$emp_email','$emp_number','$emp_address','$emp_district','$emp_prefecture','$emp_province','$emp_id_card'"
. ",'$emp_image','$emp_status')";
$result1 = mysqli_query($con, $sql);
if ($result1) {
echo "<script>alert('บันทึกข้อมูลเรียบร้อยแล้ว');window.location='Manage_Emp.php';</script>";
} else {
echo "<script>alert('บันทึกข้อมูลไม่สำเร็จ');window.location='Add_Emp.php';</script>";
}
}
Tag : PHP, HTML5, JavaScript, Ajax, jQuery

|
ประวัติการแก้ไข 2018-11-25 01:44:33
|
 |
 |
 |
 |
Date :
2018-11-25 01:43:27 |
By :
worapong39 |
View :
628 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 01
|