|
|
|
[PHP] [AJAX] การอับโหลดรูปภาพส่งค่าโดยใช้ ajax ลงฐานข้อมูล |
|
|
|
|
|
|
|
ดูฟอร์มที่ทำหน่อยครับ
|
|
|
|
|
Date :
2015-11-25 14:19:05 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/simple-sidebar.css" rel="stylesheet">
<link href="css/fileinput.css"all" rel="stylesheet" type="text/css" />
<!-- jQuery -->
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
<script src="js/fileinput.js" type="text/javascript"></script>
<script src="js/fileinput_locale_fr.js" type="text/javascript"></script>
<script src="js/fileinput_locale_es.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/jquery.form.js"></script>
<!--<script src="js/bootstrap.min.js"></script>-->
<script src="scripts/jqFunction.js"></script>
<script type="text/javascript" src="tinymce/tinymce.min.js"></script>
<?php
session_start();
include("class//class.common.php");
include ('allfunction.php');
$mode ="<h3>เพิ่ม CSR</h3>";
$vdoid="";
$vdoName="";
if (!empty($_POST['HDACT'])){
$mode = "<h3>แก้ไขสินค้า</h3>";
//print_r($_POST); SELECT * FROM `tvc_video`
$sql = "SELECT * FROM tvc_video WHERE tvc_id = '{$_POST['HDTVC_ID']}'";
$hp = new Helper();
$dt = new dataTable();
$hp->ExcuteForDataTable($sql);
$dt->setResultSet($hp->getDtResult());
$vdoid= $dt->getData(0,"tvc_id");
$vdoName= $dt->getData(0,"productDesc");
}
?><div id="wrapper">
<?php include_once 'menu.php';?>
<div id="page-content-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<form id="myform" id="myform" method="post" enctype="multipart/form-data">
<div name="divmode" id="divmode"></div>
<table width="872" height="236" border="0">
<tr>
<td width="136" height="39"><strong>รหัส :</strong></td>
<td width="6"> </td>
<td width="150">
<?php
$txtvdoid = new textbox();
$txtvdoid->setEnable(FALSE);
$txtvdoid->setWidth(15);
$txtvdoid->setBgColor("yellow");
$txtvdoid->setID("txtvdoid");
$hp1= new Helper();
$dt1= new dataTable();
$hp1->ExcuteForDataTable("select MAX(tvc_id)+1 from tvc_video");
$dt1->setResultSet($hp1->getDtResult());
$a=$dt1->getDataIndex(0,0);
$txtvdoid->setValue($a);
$txtvdoid->show();
?>
</td>
</tr>
<tr>
<td height="39"><strong>ชื่อวีดีโอ :</strong></td>
<td> </td>
<td>
<img src="uploads/CSR/<?=$_SESSION['upl'];?>" width="250" height="150>
</td>
</tr>
<tr>
<td height="39"><strong>VDO link :</strong></td>
<td> </td>
<td><?php
$txtvdolink = new textbox();
$txtvdolink->setWidth(15);
$txtvdolink->setID("txtvdolink");
$txtvdolink->show();
?></td>
</tr>
</table>
<br><br>
<?php
$btnSave = new textbox();
$btnSave->setTypeInput("button");
$btnSave->setClass("btn btn-primary");
$btnSave->setValue("ตกลง");
$btnSave->setID("btnSave");
$btnSave->show();
?>
<?php
$btnBack = new textbox();
$btnBack->setTypeInput("button");
$btnBack->setClass("btn btn-danger");
$btnBack->setValue("ย้อนกลับ");
$btnBack->setID("btnBack");
$btnBack->show();
?>
<div name="gvshow" id="gvshow" ></div>
</br>
<input type="file" name="upl[]" id="upl" class="file" multiple />
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript">
<?php
echo showValueHtml("divmode", $mode);
//echo showValue("txtvdoid", $vdoidMax);
?>
$("#btnSave").click(function(){
var isValid = true;
$('#txtvdolink').each(function () {
if ($.trim($(this).val()) == '') {
isValid = false;
$(this).css({
"border": "1px solid red",
"background": "#FFCECE"
});
alert("กรุณากรอกข้อมูลให้ครบ");
}
else {
$(this).css({
"border": "",
"background": ""
});
}
});
if (isValid == false){
e.preventDefault();
}
if($("#divmode").html() !== "<h3>แก้ไขวีดีโอ TVC</h3>")
modestr = "insert";
else
modestr = "edit";
//var formData = new FormData($("#upl")[0]);
ajaxfunc("POST","action.AddEditMedia.php",$("#myform").serialize()+"&mode=" + modestr,"error",'#gvshow');
});
</script>
|
|
|
|
|
Date :
2015-11-25 14:32:58 |
By :
newalway |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
function ajaxfunc(type,url,data,alererror,panel){
$.ajax({
type : type,//"POST",
url : url,//"action.addUser.php",
data : data,//"idsrh="+idsrh+"&modesave=functionsrh",
error : function(){
alert(alererror);
},
success : function(result){
$(panel).html(result);
}
});//ajax
}
|
|
|
|
|
Date :
2015-11-25 14:33:55 |
By :
newalway |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
action.AddEditMedia.php
<?php
session_start();
include("class//class.common.php");
include_once("class//class.ajax.ui.gridview.php");
include ("allfunction.php");
if(!empty($_POST["mode"])){
if ($_POST["mode"] == "insert"){
insert();
}elseif($_POST["mode"] == "edit"){
Edit();
}
}
function insert(){
echo $profileImg = $_FILES['upl'];
echo $strsql = "Insert Into tvc_video(tvc_name,tvc_video_link,tvc_createdate,tvc_createName)";
$strsql .= " values(:tvc_name,
:tvc_video_link,
now(),
:tvc_createName
)";
$paras = array();
//print_r( $_POST);
$i = 0;
/*if(copy($_FILES["file"]["tmp_name"],"Image/".$_FILES["file"]["name"]))
{*/
$paras[$i] = new paramter(":tvc_name");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue($profileImg);
$i++;
/*}*/
$paras[$i] = new paramter(":tvc_video_link");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue($_POST['txtvdolink']);
$i++;
$paras[$i] = new paramter(":tvc_createName");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue("Admin");
$i++;
print_r($paras);
$hp = new Helper();
$hp->ExcuteNonQueryPara($strsql, $paras);
//echo $hp->getStatus();
if ($hp->getEffectRow() == -1){
echo "<script language='javascript'> \n";
//echo $hp->getStatus();
echo "</script>";
}else{
MessageBox ($hp->getEffectRow());
MessageBox("เพิ่มข้อมูลเรียบร้อยเเล้ว");
}
$hp->__destruct();
startScript();
//echo "window.location='AddEditMedia.php'";
endScript();
}
function Edit(){
$strsql = "update productpos SET
productDesc = :productDesc,
productName = :productName,
productEng = :productEng,
productType = :productType,
productBrand = :productBrand,
Productuom = :Productuom,
productCost = :productCost,
productPrice = :productPrice,
PicProduct = :PicProduct
Where productId = :productId";
$paras = array();
$i = 0;
$paras[$i] = new paramter(":productId");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue($_POST['txtproductId']);
$i++;
$paras[$i] = new paramter(":productDesc");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue($_POST['txtadesc']);
$i++;
$paras[$i] = new paramter(":productName");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue($_POST['txtproductName']);
$i++;
$paras[$i] = new paramter(":productEng");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue($_POST['txtproductNameE']);
$i++;
$paras[$i] = new paramter(":productType");
$paras[$i]->setType(paratype::int);
$paras[$i]->setValue($_POST['ddlproductType']);
$i++;
$paras[$i] = new paramter(":productBrand");
$paras[$i]->setType(paratype::str);
$paras[$i]->setValue($_POST['txtproductBrand']);
$i++;
$paras[$i] = new paramter(":Productuom");
$paras[$i]->setType(paratype::int);
$paras[$i]->setValue($_POST['ddlproductNum']);
$i++;
$paras[$i] = new paramter(":productCost");
$paras[$i]->setType(paratype::int);
$paras[$i]->setValue($_POST['txtproductCost']);
$i++;
$paras[$i] = new paramter(":productPrice");
$paras[$i]->setType(paratype::int);
$paras[$i]->setValue($_POST['txtproductPrice']);
$i++;
$paras[$i] = new paramter(":PicProduct");
$paras[$i]->setType(paratype::int);
if ($_POST["htest"] == "yes")
$paras[$i]->setValue(1);
else
$paras[$i]->setValue(0);
$i++;
//print_r($paras);
$hp = new Helper();
$hp->ExcuteNonQueryPara($strsql, $paras);
//echo $hp->getStatus();
if ($hp->getEffectRow() == -1){
echo "<script language='javascript'> \n";
//echo $hp->getStatus();
echo "</script>";
}else{
MessageBox ($hp->getEffectRow());
//$value = substr(genUserID(),-3);
//$hp->ExcuteForDataTable("UPDATE countrun SET couNum = couNum+1 WHERE couId=4");
MessageBox("แก้ไขเรียบร้อยแล้ว");
/*echo "<script language='javascript'> \n";
echo "alert('Save Sucess'); \n";
echo "</script>";*/
}
$hp->__destruct();
startScript();
echo "window.location='AddEditProduct.php'";
endScript();
}
?>
|
|
|
|
|
Date :
2015-11-25 14:38:13 |
By :
newalway |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http://stackoverflow.com/questions/4545081/how-to-do-file-upload-using-jquery-serialization
|
|
|
|
|
Date :
2015-11-25 15:43:24 |
By :
NewbiePHP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|