|
|
|
ช่วยดูหน่อยครับ จะเสร็จแล้ว เหลือแค่ upload อย่างเดียว |
|
|
|
|
|
|
|
คอนเซป คือ user กรอกแบบฟอร์มร้องขอมายัง admin และ admin ตอบกลับ(ทำได้แล้ว)บางทีมันต้องมีการอัพโหลดไฟล์กลับ(ตรงนี้ที่ติด)
Code request_admin_view (อัพโหลด)(PHP)
<?php
session_start();
if($_SESSION['user_id'] == "")
{
echo "Please Login!";
exit();
}
?>
<?
$id_edit=$_GET[id_edit];
include"connect.php";
$sql="select * from pending where pen_id='$id_edit'";
$sql1="select pending.pen_fname,pending.pen_lname,pending.pen_nname,pending.teldep,pending.dep_name,pending.pos_name,pending.pen_name,pending.pen_notes,
pending.pen_admin,pending.pen_notes_admin,pending.pen_status,pending.pen_upload
from pending where pending.pen_id='$id_edit'";
$result=mysql_db_query($dbname,$sql);
@$rs=mysql_fetch_array($result);
$fname=$rs[fname];
$lname=$rs[lname];
$nname=$rs[nname];
$teldep=$rs[teldep];
$dep_name=$rs[dep_name];
$pos_name=$rs[pos_name];
$pen_name=$rs[pen_name];
$pen_notes=$rs[pen_notes];
$pen_admin=$rs[pen_admin];
$pen_notes_admin=$rs[pen_notes_admin];
$pen_status=$rs[pen_status];
$pen_upload=$rs[pen_upload];
?>
<?
include"connect.php";
$sql="select * from pending ORDER BY pen_id ASC";
$result=mysql_db_query($dbname,$sql);
$number=mysql_num_rows($result);
$no=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>การร้องขอเอกสาร</title>
<link rel="shortcut icon" href="images/hospital.png"/>
<style>
body {
background: url('images/bg.jpg') top center ;
background-attachment:fixed;
background-size: 100%;
background-origin: content;
background-repeat: no-repeat;
}
.auto-style2 {
text-align: center;
font-size: x-large;
}
</style>
</head>
<body>
<div><a href="page_admin.php"><img src='images/manage/1440760696_home.png' width='40px' height='40px' style="float: right" /></a></div>
<br/><br/><br/>
<form name="form1" method="post" action="request_admin_view_add.php">
<table style="background-size: 100% 100%; width: 580px; background-image: url('images/KPK4PR-3.png'); background-repeat: no-repeat; background-attachment: scroll; height: 550px;" align="center">
<tr>
<td colspan="6" style="height: 240px"></td>
</tr>
<tr>
<td style="height: 40px"></td>
<td style="height: 40px; " colspan="4" class="auto-style2"><strong>ร้องขอเอกสาร</strong></td>
<td style="height: 40px"></td>
</tr>
<tr>
<td style="height: 10px"></td>
<td style="background-position: center center; background-size: 100% 100%; height: 10px; background-image: url('images/line.png'); background-repeat: no-repeat;" colspan="4" class="auto-style2"></td>
<td style="height: 10px"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> ชื่อ</strong></td>
<td style="width: 155px; height: 35px;"><input name="fname" value="<?=$fname?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 75px; height: 35px;"><strong> สกุล</strong></td>
<td style="width: 165px; height: 35px;"><input name="lname" value="<?=$lname?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> ชื่อเล่น</strong></td>
<td style="width: 155px; height: 35px;"><input name="nname" value="<?=$nname;?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 75px; height: 35px;"><strong> ติดต่อ</strong></td>
<td style="width: 165px; height: 35px;"><input name="teldep" value="<?=$teldep;?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> แผนก</strong></td>
<td style="height: 35px; " colspan="3"><input name="dep_name" value="<?=$dep_name;?>" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> ตำแหน่ง</strong></td>
<td style="height: 35px; " colspan="3"><input name="pos_name" value="<?=$pos_name;?>" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> เรื่องที่ขอ</strong></td>
<td style="height: 35px;" colspan="3" ><input name="pen_name" value="<?=$pen_name;?>" placeholder=" พิมพ์คำบรรยายคราวๆ" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px"></td>
</tr>
<tr style="border-bottom-style: dotted">
<td style="width: 50px; height: 50px;"></td>
<td style="width: 85px; height: 50px;"><strong> หมายเหตุ</strong></td>
<td style="height: 50px;" colspan="3"><textarea name="pen_notes" placeholder=" พิมพ์เพิ่มเติม ละเอียด" style="width: 91.5%; height: 90%" disabled><?=$pen_notes;?></textarea></td>
<td style="width: 50px; height: 50px;"></td>
</tr>
<tr style="border-bottom-style: dotted">
<td style="width: 50px; height: 10px;"></td>
<td style="background-position: center; background-size: 100% 100%; height: 10px; background-image: url('images/line.png'); background-repeat: no-repeat;" colspan="4"></td>
<td style="height: 10px;"></td>
</tr>
<!---------------------------------------------------------------------------------------------------------------------------------------------------------->
<?
$strSQL = "SELECT * FROM member WHERE user_id = '".$_SESSION['user_id']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> Admin</strong></td>
<td style="height: 35px;" colspan="3"><input name="pen_admin" value="<?php echo $objResult["fname"];?> <?php echo $objResult["lname"];?>" placeholder=" ชื่อ-สกุล ของ Admin" style="height: 90%; width: 92%" type="text" /></td>
<td style="width: 50px; height: 35px"></td>
</tr>
<tr>
<td style="height: 50px;"></td>
<td style="height: 50px;"><strong> หมายเหตุ</strong></td>
<td style="height: 50px;" colspan="3"><textarea name="pen_notes_admin" placeholder=" ตอบกลับเพิ่มเติม จาก Admin" style="width: 91.5%; height: 90%" ><?=$pen_notes_admin;?></textarea></td>
<td style="height: 50px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> สถานะ</strong></td>
<td style="height: 35px;" colspan="3">
<select name="pen_status" value="<?=$pen_status;?>" style="width: 93%; height: 90%">
<option> รอดำเนินการ</option>
<option> กำลังค้นหา</option>
<option> เสร็จสิ้น</option>
</select></td>
<td style="width: 50px; height: 35px"></td>
</tr>
<form name="form2" action="request_admin_view_upload.php" method="post" enctype="multipart/form-data">
<tr>
<td style="width: 50px; height: 30px;"></td>
<td style="width: 85px; height: 30px;"></td>
<td style="height: 30px;" colspan="3"><input name="file[]" type="file" id="file[]"/></td>
<td style="width: 50px; height: 30px"></td>
</tr>
<tr>
<td style="height: 30px;" colspan="6"><center>
<?
if($pen_status==" เสร็จสิ้น"){
echo"<input type='submit' name='submit' value='Submit' disabled>";
}else{
echo"<input type='submit' name='submit' value='Submit'><INPUT NAME='id_edit' TYPE='hidden' VALUE='$id_edit'>";
}
?>
</center></td>
</tr>
<tr>
<td style="height: 15px;" colspan="6"></td>
</tr>
</form>
</table>
</form>
</body>
</html>
Code request_admin_view_upload (PHP)
<style>
body {
background: url('images/bg.jpg') top center ;
background-attachment:fixed;
background-size: 100%;
background-origin: content;
background-repeat: no-repeat;
}
</style>
<?php
//เชื่อมต่อฐานข้อมูลด้วย mysqli
$db = new mysqli("localhost", "root", "1234", "dbboard");
if(mysqli_connect_errno()) die("Connect Failed! :" . mysqli_connect_error());
$db->set_charset("utf8");
if(isset($_POST['Submit'] ))
{
$num_file = count($_FILES['file']['name']);
$select = false;
$count = 0;
for($i = 0; $i < $num_file ; $i++) //เนื่องจาก upload แบบ array เราจึงใช้ loop จัดการทีละไฟล์
{
if($_FILES['file']['error'][$i] != 0) //ถ้าเกิดข้อผิดพลาดให้ข้ามไฟล์นนี้ไป
{
$count++;
continue;
}
if($_FILES['file']['name'][$i] != "")
{
$Filename = $_FILES['file']['name'][$i];
$type = $_FILES['file']['type'][$i];
//เก็บชื่อไฟล์เป็นเวลาขณะที่ upload แล้วตามด้วยนามสกุลไฟล์ ถ้าไฟล์มีชื่อเหมือนกันจะได้ไม่มีปัญหา
//สามารถ upload ไฟล์นามสกุล .gif, .png, .jpg, .zip, .docx, .pdf, .doc, .swf, .rar ได้
$time = time() * microtime();
if ( $type == "image/gif" ) {$Filename = $time.".gif"; $pic_type = 'GIF'; }
else if ( $type == "image/png" ) {$Filename = $time.".png"; $pic_type = 'PNG'; }
else if (( $type == "image/jpg") or ($type=="image/jpeg") or ($type == "image/pjpeg")) {$Filename = $time.".jpg"; $pic_type = 'JPG'; }
else if ($type == "application/octet-stream" ) {$Filename = $time.".zip"; $pic_type = false;}
else if ($type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ) {$Filename = $time.".docx"; $pic_type = false;}
else if ($type == "application/pdf" ) {$Filename = $time.".pdf"; $pic_type = false;}
else if ($type == "application/msword" ) {$Filename = $time.".doc"; $pic_type = false;}
else if ($type == "application/x-shockwave-flash" ) {$Filename = $time.".swf"; $pic_type = false;}
else if($type == "application/octet-stream" ) {$Filename = $time.".rar"; $pic_type = false;}
//move ไฟล์ไปยังโฟลเดอร์ที่สร้างไว้ในที่นี้คือ fileupload
if(move_uploaded_file($_FILES['file']['tmp_name'][$i], 'fileRequestUpload/'.$Filename)){
//จัดเก็บชื่อไฟล์ลงฐานข้อมูล
$sql = $db->query("INSERT INTO pending (pen_upload) VALUES ('{$Filename}') ");
if($sql)
{
echo "Upload สำเร็จ <br>";
$upload_true = true;
}else{
echo "Upload ล้มเหลว!! <br>";
}
}
}else{
$count++;
}
}
if($upload_true)
echo "<a href='#'>View file</a>";
}else{
echo "คุณยังไม่ได้เลือกไฟล์ Upload";
}
?>
Code request_admin_view_add (ทำได้แล้ว)(PHP)
<style>
body {
background: url('images/bg.jpg') top center ;
background-attachment:fixed;
background-size: 100%;
background-origin: content;
background-repeat: no-repeat;
}
</style>
<?
$id_edit=$_POST[id_edit];
$pen_admin=$_POST[pen_admin];
$pen_notes_admin=$_POST[pen_notes_admin];
$pen_status=$_POST[pen_status];
$pen_upload=$_POST[pen_upload];
include"connect.php";
$sql="update pending set pen_admin='$pen_admin',pen_notes_admin='$pen_notes_admin',pen_status='$pen_status',pen_upload='$pen_upload' where pen_id='$id_edit'";
$result=mysql_db_query($dbname,$sql);
if($result){
echo"<H3><CENTER><br><br><br><br><br><img src='images/thumbsup.png' width='256px' height='161px'></CENTER></H3>";
echo"<META HTTP-EQUIV=refresh CONTENT=\"1; URL=page_admin.php\">";
}else{
echo"<H3>ERROR:Can not fix</H3>";
}
Mysql_close();
?>
Code request_user_view (พื้นที่จะให้ upload แสดง)(PHP)
<?
$id_edit=$_GET[id_edit];
include"connect.php";
$sql="select * from pending where pen_id='$id_edit'";
$result=mysql_db_query($dbname,$sql);
$rs=mysql_fetch_array($result);
$pen_id=$rs[pen_id];
$fname=$rs[fname];
$lname=$rs[lname];
$nname=$rs[nname];
$dep_name=$rs[dep_name];
$teldep=$rs[teldep];
$pos_name=$rs[pos_name];
$pen_name=$rs[pen_name];
$pen_notes=$rs[pen_notes];
$pen_admin=$rs[pen_admin];
$pen_notes_admin=$rs[pen_notes_admin];
$pen_status=$rs[pen_status];
$pen_upload=$rs[pen_upload];
?>
<?
include"connect.php";
$sql="select * from pending ORDER BY pen_id ASC";
$result=mysql_db_query($dbname,$sql);
$number=mysql_num_rows($result);
$no=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>การร้องขอเอกสาร</title>
<link rel="shortcut icon" href="images/hospital.png"/>
<style>
body {
background: url('images/bg.jpg') top center ;
background-attachment:fixed;
background-size: 100%;
background-origin: content;
background-repeat: no-repeat;
}
*html, body{
margin:0px;
padding:0px;
}.auto-style2 {
text-align: center;
font-size: x-large;
}
</style>
</head>
<body>
<div><a href="page_user.php"><img src='images/manage/1440760696_home.png' width='40px' height='40px' style="float: right" /></a></div>
<br/><br/><br/>
<form name="form1" method="post" action="">
<table style="background-size: 100% 100%; width: 580px; background-image: url('images/KPK4PR-3.png'); background-repeat: no-repeat; background-attachment: scroll; height: 550px;" align="center">
<tr>
<td colspan="6" style="height: 234px"></td>
</tr>
<tr>
<td style="height: 40px"></td>
<td style="height: 40px; " colspan="4" class="auto-style2"><strong>ร้องขอเอกสาร</strong></td>
<td style="height: 40px"></td>
</tr>
<tr>
<td style="height: 10px"></td>
<td style="background-position: center center; background-size: 100% 100%; height: 10px; background-image: url('images/line.png'); background-repeat: no-repeat;" colspan="4" class="auto-style2"></td>
<td style="height: 10px"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> ชื่อ</strong></td>
<td style="width: 155px; height: 35px;"><input name="fname" value="<?=$fname;?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 75px; height: 35px;"><strong> สกุล</strong></td>
<td style="width: 165px; height: 35px;"><input name="lname" value="<?=$lname;?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> ชื่อเล่น</strong></td>
<td style="width: 155px; height: 35px;"><input name="nname" value="<?=$nname;?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 75px; height: 35px;"><strong> ติดต่อ</strong></td>
<td style="width: 165px; height: 35px;"><input name="teldep" value="<?=$teldep;?>" style="height: 90%; width: 80%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> แผนก</strong></td>
<td style="height: 35px; " colspan="3"><input name="dep_name" value="<?=$dep_name;?>" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> ตำแหน่ง</strong></td>
<td style="height: 35px; " colspan="3"><input name="pos_name" value="<?=$pos_name;?>" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> เรื่องที่ขอ</strong></td>
<td style="height: 35px;" colspan="3" ><input name="pen_name" value="<?=$pen_name;?>" placeholder=" พิมพ์คำบรรยายคราวๆ" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px"></td>
</tr>
<tr style="border-bottom-style: dotted">
<td style="width: 50px; height: 49px;"></td>
<td style="width: 85px; height: 49px;"><strong> หมายเหตุ</strong></td>
<td style="height: 50px;" colspan="3" valign="top" scope="col"><textarea name="pen_notes" placeholder=" พิมพ์เพิมเติม ให้ละเอียด" style="width: 91.5%; height: 90%" disabled><?=$pen_notes;?></textarea></td>
<td style="width: 50px; height: 49px;"></td>
</tr>
<tr style="border-bottom-style: dotted">
<td style="width: 50px; height: 10px;"></td>
<td style="background-position: center; background-size: 100% 100%; height: 10px; background-image: url('images/line.png'); background-repeat: no-repeat;" colspan="4"></td>
<td style="height: 10px;"></td>
</tr>
<!---------------------------------------------------------------------------------------------------------------------------------------------------------->
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> Admin</strong></td>
<td style="height: 35px;" colspan="3"><input name="pen_admin" value="<?=$pen_admin;?>" placeholder=" ชื่อ-สกุล ของ Admin" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px"></td>
</tr>
<tr>
<td style="height: 50px;"></td>
<td style="height: 50px;"><strong> หมายเหตุ</strong></td>
<td style="height: 50px;" colspan="3" valign="top" scope="col"><textarea name="pen_notes_admin" placeholder=" ตอบกลับเพิ่มเติม จาก Admin" style="width: 91.5%; height: 90%" disabled><?=$pen_notes_admin;?></textarea></td>
<td style="height: 50px;"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> สถานะ</strong></td>
<td style="height: 35px;" colspan="3"><input name="pen_status" value="<?=$pen_status;?>" placeholder=" รอการเปลี่ยนแปลงสถานะ จาก Admin" style="height: 90%; width: 92%" type="text" disabled/></td>
<td style="width: 50px; height: 35px"></td>
</tr>
<tr>
<td style="width: 50px; height: 35px;"></td>
<td style="width: 85px; height: 35px;"><strong> ไฟล์</strong></td>
<td style="height: 35px;" colspan="3">
<?php
//เชื่อมต่อฐานข้อมูลด้วย mysqli
//$db = new mysqli("localhost", "root", "1234", "dbboard");
if(mysqli_connect_errno()) die("Connect Failed! :" . mysqli_connect_error());
//$db->set_charset("utf8");
//$sql = $db->query("SELECT * FROM pending");
echo "<table border = 1 cellpadding = 5 cellspacing = 1> <tr>"; //แสดงข้อมูลด้วยตาราง
$rows = 0;
//while($result = $sql->fetch_object()){ //วนลูปแสดงข้อมูล
echo "<td>";
$rows++;
$type = substr($result->pen_upload,-3); //ตัดเอาเฉพาะชื่อไฟล์ 3 ตัวสุดท้าย
if($type == 'jpg' or $type == 'png' or $type == 'gif'){
//ถ้าเป็นไฟล์รูปภาพให้แสดงเป็นรูปภาพพร้อมทั้ง link download
?>
<img src="fileRequestUpload/<?php echo $result->pen_upload; ?>"/>
<?php
//ถ้าไม่ใช่ไฟล์รูปภาพให้แสดงเป็นชื่อไฟล์พร้อมทั้ง link download
}else{ ?>
<a href="fileRequestUpload/<?php echo $result->pen_upload; ?>"><?php echo $result->pen_upload; ?></a>
<?php
}
echo"</td>";
if(($rows)%2==0)
{
echo"<tr></tr>";
}
//}
echo"</tr></table>";
?>
</td>
<td style="width: 50px; height: 35px"></td>
</tr>
<tr>
<td style="height: 30px;" colspan="6"><INPUT TYPE="hidden" NAME="id_edit" VALUE="<?=$pen_id;?>" /></td>
</tr>
</table>
</form>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2015-09-19 16:08:42 |
By :
NuItMaster |
View :
890 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พอมีใครช่วยดูได้บ้างไหมครับ
|
|
|
|
|
Date :
2015-09-19 19:06:04 |
By :
NuItMaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำไมถึงใช้ <form> ซ้อน <form> สองรอบครับ
|
|
|
|
|
Date :
2015-09-20 09:23:56 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|