อัพโหลดรูปลงในอัลบั้มครั้งล่ะหลายรูปเเต่บันทึกลงฐานข้อมูลเเค่รูปเดียว

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา อัพโหลดรูปลงในอัลบั้มครั้งล่ะหลายรูปเเต่บันทึกลงฐานข้อมูลเเค่รูปเดียว

อัพโหลดรูปลงในอัลบั้มครั้งล่ะหลายรูปเเต่บันทึกลงฐานข้อมูลเเค่รูปเดียว

อัพโหลดรูปใส่ในอัลบั้มครั้งล่ะหลายรูป เเต่รูปบันทึกลงฐานข้อมูลเพียงรูปเดียว รบกวนช่วยดูโค้ดให้หน่อยนะค่ะ ไม่ทราบผิดตรงไหน

ไฟล์ gallery_create.php

 

<script language="javascript">
	function fncCreateElement(){
		
	   var mySpan = document.getElementById('mySpan');
		
		var myElement1 = document.createElement('input');
		myElement1.setAttribute('type',"file");
		myElement1.setAttribute('name',"filGalleryShot[]");
		//myElement1.setAttribute('id',"filUpload[]");
		mySpan.appendChild(myElement1);	   

		//*** Remove Element ***//
		/*
		var deleteEle = document.getElementById('txt1');
		mySpan.removeChild(deleteEle);
		*/

	   var myElement2 = document.createElement('<br>');
	   mySpan.appendChild(myElement2);
	}
</script>

<div id='newsfeed_contain'>
<div class='block_news_add_new'>

<form id="form1" name="form1" method="post" enctype="multipart/form-data" action="save_gallery.php?AlbumID=<?=$_GET["AlbumID"];?>" >

<div class="panel panel-default">

<div class="panel-body">
<table width='650px' >
<tr>
<td valign='top' width="160px" ><label>รูปภาพ:</label></td>
<td valign='top'>
<span>
<!--    <input type="text" name="txtGalleryName1">-->
    <span style="float:left"><input type="file" name="filGalleryShot[]"/></span>
    <span style="float:left"> <input name="btnButton" id="btnButton" type="button" value="+" onClick="JavaScript:fncCreateElement();"></span>
	<br>
	<span id="mySpan"></span>
</td>
</tr>
</table>
</div>

<div class="panel-body">
<table width='650px' >
<tr>
<td colspan="2" valign='top'> <input name="Submit" type="submit" class="btn btn-default" id="Submit" value="   เพิ่มรูปภาพ   " /> 
<input name="Cancel" type="button" value="ยกเลิกการเพิ่มรูปภาพ" onClick="window.location='gallery_upload.php'" class="btn btn-default"/ > 
</td>
</tr>
</table>
</div>
  
</div>

    </form>
           
</div>

</div>

ไฟล์ save_gallery.php

 

<?
for($i=0;$i<count($_FILES["filGalleryShot"]["name"]);$i++)
	{
		if($_FILES["filGalleryShot"]["name"][$i] != "")
		{
			if(move_uploaded_file($_FILES["filGalleryShot"]["tmp_name"][$i],"album_pic/".$_FILES["filGalleryShot"]["name"][$i]))
			{
				//*** Insert Record ***//
				$strSQL = "INSERT INTO files ";
				$strSQL .="(AlbumID,GalleryShot) VALUES ('".$_GET["AlbumID"]."','".$_FILES["filGalleryShot"]["name"][$i]."')";
			}
		}
	}
	
	
	
	if(mysql_query($strSQL)){
		echo "<script language="JavaScript">";
		echo "alert('เพิ่มรูปเรียบร้อยเเล้วค่ะ');";
		echo "</script>";
		echo "<meta http-equiv='refresh'content='0;URL=album_manage.php'>";
		}
		else{
		echo "<meta http-equiv='refresh'content='1;URL=profile_wall.php'>";
		}
?>

 



Nathakarn 180.183.124.xxx 14-12-2014 01:28:45

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
คำสั่ง query อยู่นอกลูป แสดงว่าไม่ได้ทำงานบันทึกแต่ละรูป แต่ไปบันทึกรูปสุดท้ายแทน
ใช้แบบนี้แทน

<?
$status_upload=0;
for($i=0;$i<count($_FILES["filGalleryShot"]["name"]);$i++)
	{
		if($_FILES["filGalleryShot"]["name"][$i] != "")
		{
			if(move_uploaded_file($_FILES["filGalleryShot"]["tmp_name"][$i],"album_pic/".$_FILES["filGalleryShot"]["name"][$i]))
			{
				//*** Insert Record ***//
				$strSQL = "INSERT INTO files ";
				$strSQL .="(AlbumID,GalleryShot) VALUES ('".$_GET["AlbumID"]."','".$_FILES["filGalleryShot"]["name"][$i]."')";
                mysql_query($strSQL);
                $status_upload++;
			}
		}
	}
	
	
	
	if($status_upload>0){
		echo "<script language="JavaScript">";
		echo "alert('เพิ่มรูปเรียบร้อยเเล้วค่ะ');";
		echo "</script>";
		echo "<meta http-equiv='refresh'content='0;URL=album_manage.php'>";
		}
		else{
		echo "<meta http-equiv='refresh'content='1;URL=profile_wall.php'>";
		}
?>



ninenik 1.47.144.xxx 14-12-2014
 ความคิดเห็นที่ 2
^^ ขอบคุณค่ะ เเก้ได้เเล้วค่ะ


nathakarn 180.183.55.xxx 14-12-2014 16:15






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ