|
|
|
รบกวนถามเรื่องการอัพโหลดไฟล์ทีคับ คือว่าผมต้องการจะบันทึกชื่อไฟล์ลงไปในฐานข้อมูลน่ะคับ ต้องทำยังไงบ้าง |
|
|
|
|
|
|
|
คือว่าผมต้องการจะบันทึกชื่อไฟล์ลงไปในฐานข้อมูลน่ะคับ
ต้องทำยังไงบ้าง
*********************************************************************
//นี้คือโค๊ดที่ผมใช้เขียนหน้าฟอร์มน่ะคับ//
<?php require_once('Connections/db1.php'); ?><?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO data (heading, detail, `group`, name, date_time, ip) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['heading'], "text"),
GetSQLValueString($_POST['detail'], "text"),
GetSQLValueString($_POST['grop'], "text"),
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['date'], "text"),
GetSQLValueString($_POST['ip'], "text"));
mysql_select_db($database_db1, $db1);
$Result1 = mysql_query($insertSQL, $db1) or die(mysql_error());
$insertGoTo = "all_view.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_db1, $db1);
$query_Recordset1 = "SELECT * FROM `data` ORDER BY id ASC";
$Recordset1 = mysql_query($query_Recordset1, $db1) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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 http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>ส่งข่าว</title>
<style type="text/css">
<!--
.style1 {font-size: 24px}
.style2 {color: #0000FF}
.style6 {
color: #99FFFF;
font-size: 12px;
}
#Layer1 {
position:absolute;
left:682px;
top:111px;
width:206px;
height:223px;
layer-background-color:#00FFFF;
border:1px none #000000;
z-index:1;
}
body {
background-color: #FFCCFF;
}
-->
</style>
</head>
<body>
<div id="Layer1"><img src="img/News.gif" width="282" height="231" /></div>
<h3>
<div align="center" class="style1 style2">แจ้งข่าวสารประชาสัมพันธ์</div>
</h3>
<fieldset><legend class="style2">ข้อมูล</legend>
<form action="<?php echo $editFormAction; ?><form.php>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<table width="670" border="0">
<tr>
<td width="121" class="style2">หัวข้อ</td>
<td width="24" class="style2">:</td>
<td width="503" class="style2"><input name="heading" type="text" id="heading" size="62" /></td>
</tr>
<tr>
<td valign="top" class="style2">รายละเอียด</td>
<td valign="top" class="style2">:</td>
<td class="style2"><textarea name="detail" cols="62" rows="7" id="detail"></textarea></td>
</tr>
<tr>
<td valign="top" class="style2">ชื่อผู้เขียน</td>
<td valign="top" class="style2">:</td>
<td class="style2"><input name="name" type="text" id="name" size="62" />
<input name="date" type="hidden" id="date" value="<?php echo date("d-m-Y H:i:s");?>" />
<input name="ip" type="hidden" id="ip" value="<?php echo $_SERVER['REMOTE_ADDR'];?>" /></td>
</tr>
<tr>
<td class="style2">กลุ่มงาน</td>
<td class="style2">:</td>
<td class="style2"><select name="grop" id="grop">
<option selected="selected">----------เลือก---------</option>
<option>หน้าห้องผู้อำนวยการ</option>
<option>กลุ่มงานอำนวยการ</option>
<option>กลุ่มงานบุคคล</option>
<option>กลุ่มนโยบานและแผน</option>
<option>กลุ่มงานส่งเสริมการจัดการศึกษา</option>
<option>กลุ่มงานส่งเสริมศึกษาเอกชน</option>
<option>กลุ่มงานหน่วยตรวจสอบภายใน</option>
<option>กลุ่มงานICT</option>
</select>
</td>
</tr>
<tr>
<td class="style2">แนบไฟล์</td>
<td class="style2">:</td>
<td class="style2"><input name="File" type="file" id="File" size="50" /></td>
</tr>
</table>
<p class="style2">
<input type="submit" name="Submit" value="ส่งข่าว" />
<input type="reset" name="Submit2" value="ยกเลิก" />
<input type="hidden" name="MM_insert" value="form1">
<input name="hiddenField" type="hidden" value="echo "<br>$File_name"; " />
</p>
</form>
<?php
// Upload full path (Detect path automatically)
if (!defined('UPLOADDIR')) define('UPLOADDIR', (dirname(__FILE__) ."/uploadfiles") );
?></span>
<span class="style2">
<?php
//checks if file uploaded
if (is_uploaded_file($_FILES['File']['tmp_name'])) {
$File_tmpname = $_FILES["File"]["tmp_name"];
$File_name = $_FILES["File"]["name"];
$File_type = $_FILES["File"]["type"];
$File_extension = substr($File_type,(strrpos($File_type,"/")+1));
$File_size = $_FILES["File"]["size"];
//checks if file moved successfull
if ( move_uploaded_file($File_tmpname, (UPLOADDIR . "/" . $File_name)) ) {
echo "<br>File uploading $File_name successful.";
}
else {
echo "<br>File uploading failure.";
}
}
?>
</span>
</fieldset>
<table width="958" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="42" height="36"> </td>
<td width="867" valign="top"><div align="center">
<p><br />
<img src="img/054.gif" width="60" height="45" /><img src="img/054.gif" width="60" height="45" /><img src="img/054.gif" width="60" height="45" /><img src="img/054.gif" width="60" height="45" /><img src="img/054.gif" width="60" height="45" /><img src="img/054.gif" width="60" height="45" /><img src="img/054.gif" width="60" height="45" /></p>
<p> </p>
<hr />
<span class="style6">copyrigth all by [email protected] 2009</span></div></td>
<td width="49"> </td>
</tr>
<tr>
<td height="21"></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-05-12 13:27:08 |
By :
ioio |
View :
863 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้คำสั่ง insert ได้เลยครับแต่ถ้าเป็นรูปครวที่จะเก็บชื่อรูปไว้ใน db ด้วยน่ะครับ
|
|
|
|
|
Date :
2009-05-12 16:00:22 |
By :
kanchen |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|