|
 |
|
เรื่อง อัพโหลดรูปภาพแล้วจะให้มันบันทึกลง db ยังไง |
|
 |
|
|
 |
 |
|
พอดี ทำโค้ด อัพโหลด รูปภาพคะ
มันติดอยู่ 2 ที่ คือ ชื่อรูปไม่มา ทำให้รูปที่อัพไปใหม่ มันทับรูปเก่า
และ เมื่ออัพโหลดได้แล้ว จะให้มันบันทึกลง db ยังไงคะ
Code (PHP)
<?php
<?php session_start();?>
<!-- Multiupload js-->
<SCRIPT LANGUAGE="JavaScript">
<!--
function addControl_browse(){
if(window.numfile){
var obj = document.getElementById('filemore');
var newO = document.createElement('div');
newO.setAttribute('id',"images");
newO.setAttribute("innerHTML", "<INPUT TYPE='file' NAME='images"+window.numfile+"' style=width:500px>");
obj.appendChild(newO);
window.numfile++;
}
document.getElementById('hdTotalBox').value = window.numfile;
}//end function
function init(){
window.numfile = 1;
}//end function
//-->
</SCRIPT>
<?php
date_default_timezone_set("Asia/Bangkok");
require_once("header.php");
require_once("config.inc.php");
require_once("utility.php");
?>
<?php
#<!--Check login -->
if(isset($_SESSION["login"])){
echo"<u>Login Pass Thank for login !!</u>";
}else{
redirect("loginUI.php");
}
?>
<?php
$nameschool=($_POST['nameschool']);
$year=($_POST['year']);
$level=($_POST['level']);
$master=($_POST['master']);
$gpa=($_POST['gpa']);
$images=($_POST['images']);
/* images */
$images_tmp=$_FILES['images0']['tmp_name'];
$images_name=$_FILES['images0']['name'];
$images_size=$_FILES['images0']['size'];
$images_type=$_FILES['images0']['type'];
$sqlcommand="insert into tb_certificate (nameschool,year,level,master,gpa) values('$nameschool','$year','$level','$master','$gpa')";
if(isset($_POST['nameschool'])){
mysql_query($sqlcommand,$conn);
redirect("certificater.php");
}
if(mysql_insert_id()>0){
echo"<u>Insert data success</u>";
}else{
echo"<u>can't insert data Please check!</u>";
}
/* check type picture */
$ext=strtolower(end(explode('.',$images_name)));
if($ext=="jpg" or $ext=="jpeg" or $ext=="gif" or $ext=="png"){
$sqlcommande="select max (id) from tb_certificate";
$result=mysql_db_query($sqlcommande,$conn);
$rec=mysql_fetch_array($result);
$id=$rec[0];
/* set new name */
$images=$id.".".$ext;
move_uploaded_file($images_tmp,"../upload/$images");
$sqlcommander="insert into tb_certificate set images='$images' where id='$id'";
mysql_query($sqlcommander,$conn);
}
?>
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY onload='init()'>
<FORM METHOD=POST ACTION="" enctype="multipart/form-data">
<INPUT TYPE="hidden" ID="hdTotalBox" name="hdTotalBox" VALUE=0>
<table width="200" border="0">
<tr>
<td style="border-right: 1px solid #000033" valign="top"><?php require_once("top.inc.php");?></td>
<td valign="top"><!-- -->
<TABLE width="300">
<TR>
<TD><div id='controlfont'>Name School :<div></TD>
<TD><INPUT TYPE="text" NAME="nameschool" style="width:500px;"><div id="controlText">*Title of performance<div></TD>
</TR>
<TR>
<TD><div id='controlfont'>Year :<div></TD>
<TD><INPUT TYPE="text" NAME="year" style="width:500px;"><div id="controlText">*Year of Graduated<div></TD>
</TR>
<TR>
<TD><div id='controlfont'>Level Education :<div></TD>
<TD><TEXTAREA NAME="level" ROWS="8" style="width:500px;"></TEXTAREA><div id="controlText">*Level Education Graduated<div></TD>
</TR>
<TR>
<TD><div id='controlfont'>Master :<div></TD>
<TD><INPUT TYPE="text" NAME="master" style="width:500px;"><div id="controlText">*Master of Education<div></TD>
</TR>
<TR>
<TD><div id='controlfont'>Images :<div></TD>
<TD><span id='filemore'><INPUT TYPE="file" NAME="images0" style="width:500px;"> </span><div id="controlText">*Images Certificate
<A HREF="#" onclick='addControl_browse()'>Add More</A><div></TD>
</TR>
<TR>
<TD><div id='controlfont'>GPA :<div></TD>
<TD><INPUT TYPE="text" NAME="gpa"><div id="controlText">*GPA<div></TD>
</TR>
<TR>
<TD></TD>
<TD><br><INPUT TYPE="submit" VALUE="submit"> <INPUT TYPE="reset"></TD>
</TR>
</TABLE><!-- -->
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-07-07 09:40:37 |
By :
nottpoo |
View :
1122 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 01
|