Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > [PHP] [AJAX] การอับโหลดรูปภาพส่งค่าโดยใช้ ajax ลงฐานข้อมูล



 

[PHP] [AJAX] การอับโหลดรูปภาพส่งค่าโดยใช้ ajax ลงฐานข้อมูล

 



Topic : 120164



โพสกระทู้ ( 68 )
บทความ ( 0 )



สถานะออฟไลน์




ผมใช้ .serialize() ไม่ผ่านครับส่งไปอีกหน้าตัวเเปรโพส อันดิฟาย พอมีใครมีตัวอย่างให้ศึกษาเเล้วเข้าใจง่ายๆๆ บ้างครับ



Tag : PHP, MySQL, Ajax, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-11-25 13:43:57 By : newalway View : 803 Reply : 5
 

 

No. 1



โพสกระทู้ ( 1,636 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ดูฟอร์มที่ทำหน่อยครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-25 14:19:05 By : NewbiePHP
 


 

No. 2



โพสกระทู้ ( 68 )
บทความ ( 0 )



สถานะออฟไลน์


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">&nbsp;</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>&nbsp;</td>
											<td>
													<img src="uploads/CSR/<?=$_SESSION['upl'];?>" width="250" height="150>
													
										</td>
											
										</tr>
									<tr>
											<td  height="39"><strong>VDO link :</strong></td>
											<td>&nbsp;</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
 

 

No. 3



โพสกระทู้ ( 68 )
บทความ ( 0 )



สถานะออฟไลน์


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
 


 

No. 4



โพสกระทู้ ( 68 )
บทความ ( 0 )



สถานะออฟไลน์


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
 


 

No. 5



โพสกระทู้ ( 1,636 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

http://stackoverflow.com/questions/4545081/how-to-do-file-upload-using-jquery-serialization
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-25 15:43:24 By : NewbiePHP
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : [PHP] [AJAX] การอับโหลดรูปภาพส่งค่าโดยใช้ ajax ลงฐานข้อมูล
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่