|
|
|
จะให้ชื่อไฟล์ที่อัพโหลด ไปเก็บในฐานข้อมูลด้วย ไฟล์เข้าไปเก็บที่ Server แต่ชื่อไฟล์ไม่ไปเก็บในฐานข้อมูล? |
|
|
|
|
|
|
|
Code (PHP)
<?ob_start();?>
<?php require_once('Connections/BookID.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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']);
}
$ext = pathinfo(basename($_FILES['file_Upload']['name']), PATHINFO_EXTENSION);
$new_file_name = 'file_'.uniqid().".".$ext;
$file_path = "myfile/";
$upload_paht = $file_path.$new_file_name;
move_uploaded_file($_FILES["file_Upload"]["tmp_name"],$upload_paht);
$fil_Upload = $new_file_name;
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO book (id, name_guide, tel, gruop, datein, dateout, DBL, TWN, TRP, remark, signature, date_save, time_save ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['id'], "int"),
GetSQLValueString($_POST['name_guide'], "text"),
GetSQLValueString($_POST['tel'], "text"),
GetSQLValueString($_POST['gruop'], "text"),
GetSQLValueString($_POST['datein'], "date"),
GetSQLValueString($_POST['dateout'], "date"),
GetSQLValueString($_POST['DBL'], "int"),
GetSQLValueString($_POST['TWN'], "int"),
GetSQLValueString($_POST['TRP'], "int"),
GetSQLValueString($_POST['remark'], "text"),
GetSQLValueString($_POST['signature'], "text"),
GetSQLValueString($_POST['date_save'], "date"),
GetSQLValueString($_POST['time_save'], "text"));
mysql_select_db($database_BookID, $BookID);
$Result1 = mysql_query($insertSQL, $BookID) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_BookID, $BookID);
$query_Recordset1 = "SELECT * FROM book";
$Recordset1 = mysql_query($query_Recordset1, $BookID) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_free_result($Recordset1);
?>
<center><form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1">
<p> </p>
<img src="insert.files/image002.jpg" width="390" height="89">
<br><br/>
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Name Guide:</td>
<td><input type="text" name="name_guide" value="" size="32"></td>
<td>Tel:
<input type="text" name="tel" value="" size="18"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Gruop:</td>
<td><input type="text" name="gruop" value="" size="32"></td>
<td>Datein: <input type="date" name="datein" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">DBL:</td>
<td><input name="DBL" type="text" size="2">
TWN
<input name="TWN" type="text" value="" size="2">
TRP
<input name="TRP" type="text" value="" size="2"></td>
<td>Dateout:
<input type="date" name="dateout" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap>Remark:</td>
<td><label for="remark"></label>
<textarea name="remark" id="remark" cols="45" rows="5"></textarea></td>
<td>
<input type="hidden" name="date_save" value="<?php echo date("Y-m-d");?>" size="32">
<input type="hidden" name="time_save" id="time_save" value="<?php echo date("H:i:s");?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Signature::</td>
<td><input type="text" name="signature" value="" size="32"></td>
<td> </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">File Name: </td>
<td><input type="file" name="file_Upload" id="file_Upload"></td>
<td><label for="textfield"></label></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Save" /></td>
<td> </td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form></center>
<p> </p>
Tag : HTML/CSS, CakePHP, Web (ASP.NET)
|
ประวัติการแก้ไข 2017-04-10 20:10:15
|
|
|
|
|
Date :
2017-04-10 20:09:10 |
By :
lovebel |
View :
729 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PHP Uploads/Download Files To MySQL Database
|
|
|
|
|
Date :
2017-04-10 22:00:38 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|