|
 |
|
การดึงไฟล์เสียงมีปัญหาค่ะ ชื่อไฟล์ที่ดึงมากับไฟล์ที่ถูกบันทึกลงในฐานไม่เหมือนกันค่ะ รบกวนช่วยแนะนำและช่วยดูโค๊ดให้หน่อยน่ะค่ะ |
|
 |
|
|
 |
 |
|
โค๊ด php ค่ะ
Code (PHP)
<? session_start();
if($_SESSION['$admin_name']=='')
{
header("Location:login.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>Insert title here</title>
<script type="text/javascript">
function closeWindow() {
opener.location.reload();
window.close();
}
</script>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>
<?
$requestMethod = $_SERVER["REQUEST_METHOD"];
$eng_id = $_GET["eng_id"];
$zone_code = $_GET["zone_id"];
//print("eng_id = $eng_id, zone_id = $zone_id");
include_once 'lib/database.php';
$db = new Database();
$result = $db->query("select * from eng where eng_id = $eng_id");
$result->fetchNext();
?>
<div><h2>รายละเอียดคำแปล</h2></div>
<div >
<?
if ($requestMethod == "POST") {
//print("post method");
$eng_id = $_POST["hdEngID"];
$zone_id = $_POST["hdZoneID"];
$word = $_POST["txtWord"];
$read = $_POST["txtRead"];
$maining = $_POST["txtMaining"];
// $groupID = $_POST["selGroupID"];
/*
NORTH
SOUTH
NORTHEAST
CENTRAL
*/
$tableName = "";
switch ($zone_code) {
case "CENTRAL":
$tableName = "rural_central";
break;
case "NORTH":
$tableName = "rural_north";
break;
case "SOUTH":
$tableName = "rural_south";
break;
case "NORTHEAST":
$tableName = "rural_northeast";
break;
}
//-- สร้างชื่อไฟล์ แบบ Random
$result = $db->query("select UUID() file_name");
$result->fetchNext();
$sound_file_name = $result->getString("file_name").".mp3";
$SQL = "insert into $tableName
(
word,
reading,
maining,
eng_id,
sound
) VALUES (
'$word',
'$read',
'$maining',
$eng_id,
'$sound_file_name'
)";
//print($SQL);
include_once 'lib/database.php';
$db = new Database();
$result = $db->execute($SQL);
if ($result->getResultStatus() == "EXECUTE_SUCCESS") {
//-- บันทึกข้อมูลไฟล์ เสียง
$type = $_FILES["fSound"]["type"];
$size = $_FILES["fSound"]["size"];
//print("type = $type, size = $size");
$save_file_message = "";
if ($type != "audio/mpeg" || $size > 512000) {
$save_file_message = "ไม่สามารถบันทึกคลิปเสียงได้ เนื่อง upload ผิดรูปแบบ";
} else {
$file_path = "sound_clip/" . $sound_file_name;
// print("begin save file name : $file_path");
move_uploaded_file($_FILES["fSound"]["tmp_name"], $file_path);
}
?>
<div style="border: solid 1px green; background-color:greenyellow; font-size: 10px">
<b>สำเร็จ</b> : บันทึกข้อมูลเรียบร้อยแล้ว, *<?=$save_file_message?>
</div>
<?
} else {
?>
<div style="border: solid 1px brown ; background-color: antiquewhite; font-size: 10px">
<b>ไม่สำเร็จ</b> : <?= $SQL ?>
</div>
<?
}
// print("eng_id =");
}
?>
</div>
<form action="#" method="post" enctype="multipart/form-data">
<table >
<tr>
<td>ศัพท์อังกฤษ</td>
<td>
<input type="hidden" id="hdEngID" name="hdEngID" value="<?= $eng_id ?>" ></input>
<input type="text" id="txtEngName" name="txtEngName" value="<?= $result->getString("eng_word") ?>" readonly="readonly"></input></td>
</tr>
<tr>
<td>ภาค</td>
<td>
<?
$resultZone = $db->query("select * from zone where zone_code = '$zone_code'");
$resultZone->fetchNext();
?>
<input type="hidden" id="hdZoneID" name="hdZoneID" value="<?= $resultZone->getString("zone_id") ?>" ></input>
<input type="text" id="txtzoneName" name="txtzoneName" value="<?= $resultZone->getString("zone_name") ?>" readonly="readonly"></input>
</td>
</tr>
<tr>
<td>คำแปล</td>
<td><input type="text" id="txtWord" name="txtWord"></input></td>
</tr>
<tr>
<td>คำอ่าน</td>
<td><input type="text" id="txtRead" name="txtRead"></input></td>
</tr>
<tr>
<td>ความหมาย</td>
<td><input type="text" id="txtMaining" name="txtMaining"></input></td>
</tr>
<tr>
<td>เสียงอ่าน </td>
<td>
<input type="file" id="fSound"name="fSound"></input> <span class="style1">*</span> รับได้เฉพาะไฟล์ .mp3 เท่านั้นค่ะ
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="บันทึกข้อมูล" ></input>
<input type="button" value="ปิดหน้าต่าง" onClick="closeWindow()"></input>
</td>
</tr>
</table>
</form>
</body>
</html>
คือ ตัวอื่นส่งค่าและบันทึกลงไม่มีปัญหาค่ะแต่ตรงไฟล์เสียงอ่านน่ะค่ะมีปัญหา คือตอนที่ดึงมาเป็นอีกชื่อหนึ่งแต่พอบันทึกลงฐานเป็นอีกชื่อหนึ่ง รบกวนช่วยหน่อยน่ะค่ะ
คืออันนี้จะเป็นการเพิ่มคำศัพท์โดยมีเงื่อนไขการเลือกเพิ่มตามภาคค่ะ
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2012-05-13 13:09:07
|
 |
 |
 |
 |
Date :
2012-05-13 13:07:15 |
By :
subai |
View :
1201 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 01
|