|  | 
	                
  
    | 
	 
        ผมสร้างไฟล์อัพโหลดรูปภาพ พร้อมฟอร์มรายละเอียดข้อความหลายภาพ  แต่อยากให้ อัพโหลดได้ทั้งหมด ในปุ่ม Submit ปุ่มเดียว ต้องทำอย่างไรครับ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | ฟอร์ม ที่อัพโหลด Code (PHP)
 
 <form action="gallery_add.php" method="post" enctype="multipart/form-data" name="form1" id="form3">
                <table width="700" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bgload.jpg">
                  <tr>
                    <td width="76" height="45"> </td>
                    <td width="7" rowspan="2"> </td>
                    <td width="218"> </td>
                    <td width="55"> </td>
                    <td width="50"> </td>
                    <td width="88"> </td>
                    <td width="67"> </td>
                    <td width="50"> </td>
                    <td width="89"> </td>
                  </tr>
                  <tr>
                    <td width="76" height="24" align="right">รูปภาพที่ 1: </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ: </td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right"><label for="date">รายละเอียด:</label></td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที:่</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="28" align="right">รูปภาพที่ 2 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="29" align="right"> รูปภาพที่ 3 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="29" align="right">รูปภาพที่ 4 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="29" align="right">รูปภาพที่ 5 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="30" align="right">รูปภาพที่ 6 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="31" align="right">รูปภาพที่ 7 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="28" align="right">รูปภาพที่ 8 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="29" align="right">รูปภาพที่ 9 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="29" align="right">รูปภาพที่ 10 : </td>
                    <td> </td>
                    <td><input name="file[]" type="file" id="file[]" /></td>
                    <td align="right">ชื่อภาพ:</td>
                    <td align="center"><input name="txtname[]" type="text" id="txtname[]" size="5" /></td>
                    <td align="right">รายละเอียด:</td>
                    <td align="center"><input name="txtdetail[]" type="text" id="txtdetail[]" size="5" /></td>
                    <td align="right">วันที่:</td>
                    <td align="center"><input name="datepicker[]" type="text" id="datepicker[]" value="" size="5" /></td>
                  </tr>
                  <tr>
                    <td height="39" colspan="9" align="center"><input type='hidden' name='ID_album' value='<?=$ID_album?>' />
                      <input type="submit" name="Submit" value="อัฟโหลดรูปภาพ" />
                            
                      <input type="button" name="button2" id="button3" value="ยกเลิก"  onclick="window.history.back();"/></td>
                  </tr>
                </table>
                <p> </p>
              </form>
 ไฟล์ save
 Code (PHP)
 
 <?php 
 include("class_dethai.php");
include ("class.imagesize.php"); 
include("conn.php");
$ID_album=$_POST[ID_album]; 
$name =$_POST[txtname];
$detail=$_POST[txtdetail];
$date1=$_POST[datepicker];
if(isset($_POST['Submit'] )) 
{ 
    $num_file = count($_FILES['file']['name']); 
    $select = false; 
    $count = 0; 
    for($i = 0; $i < $num_file ; $i++) //เนื่องจาก upload แบบ array เราจึงใช้ loop จัดการทีละไฟล์ 
    { 
        if($_FILES['file']['error'][$i] != 0) //ถ้าเกิดข้อผิดพลาดให้ข้ามไฟล์นนี้ไป 
        { 
            $count++; 
            continue; 
        } 
        if($_FILES['file']['name'][$i] != "") 
        { 
            $Filename = $_FILES['file']['name'][$i]; 
            $type = $_FILES['file']['type'][$i]; 
              //เก็บชื่อไฟล์เป็นเวลาขณะที่ upload แล้วตามด้วยนามสกุลไฟล์ ถ้าไฟล์มีชื่อเหมือนกันจะได้ไม่มีปัญหา 
          //สามารถ upload ไฟล์นามสกุล .gif, .png, .jpg, .zip, .docx, .pdf, .doc, .swf, .rar ได้ 
            $time = time() * microtime(); 
            if ( $type == "image/gif" ) {$Filename = $time.".gif"; $pic_type = 'GIF'; } 
            else if ( $type == "image/png" ) {$Filename = $time.".png"; $pic_type = 'PNG'; } 
            else if (( $type == "image/jpg") or ($type=="image/jpeg") or ($type == "image/pjpeg")){$Filename= $time.".jpg"; $pic_type = 'JPG'; } 
            else if ($type == "application/octet-stream" ) {$Filename = $time.".zip"; $pic_type = false;} 
            else if ($type == "application/vnd.openxmlformats-icedocument.wordprocessingml.document" ) {$Filename = $time.".docx"; $pic_type = false;} 
            else if ($type == "application/pdf" ) {$Filename = $time.".pdf"; $pic_type = false;} 
            else if ($type == "application/msword" ) {$Filename = $time.".doc"; $pic_type = false;} 
            else if ($type == "application/x-shockwave-flash" ) {$Filename = $time.".swf"; $pic_type = e;} 
            else if ($type == "application/octet-stream" ) {$Filename = $time.".rar"; $pic_type = false;} 
            //move ไฟล์ไปยังโฟลเดอร์ที่สร้างไว้ในที่นี้คือ fileupload 
            if(move_uploaded_file($_FILES['file']['tmp_name'][$i], 'gallery/'.$Filename)){ 
            //โค้ดในส่วนของการลดขนาดไฟล์รูปภาพ 
                if($pic_type){ 
                    $original_image = "gallery/" . $Filename ;  
                    $size = getimagesize($original_image); //ดึงขนาดของไฟล์ภาพมา 
                    $desired_height = 500 ; 
                    $desired_width = round($desired_height*$size[0]/$size[1]);
                    $image = new hft_image($original_image); 
                    $image->resize($desired_width, $desired_height, '0'); 
                    $image->output_resized("gallery/".$Filename, "JPG"); 
                } 
                //จัดเก็บชื่อไฟล์ลงฐานข้อมูล 
$sql = "INSERT INTO picture (ID_album,GalleryShot) VALUES ('$ID_album','{$Filename}');";
$rc = mysql_query($sql);
 if($rc){  
echo "บันทุึกข้อมูลเรียบร้อยแล้วครับ"; 
	 echo '<meta http-equiv="refresh" content="2;url=view_album.php">';
} else { 
echo "ไม่สามารถบันทึกข้อมูลได้ครับ";
 } 
            } 
        }else{ 
            $count++; 
        } 
    } 
}else{ 
    echo "คุณยังไม่ได้เลือกไฟล์ Upload"; 
} 
?>
 
 
 Tag : PHP, MySQL, HTML/CSS, CakePHP
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2015-12-07 14:16:32 | By :
                          godzaa | View :
                          1393 | Reply :
                          5 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | เอาเงื่อนไข if() ข้างล่างนี้ไปไว้นอก for() loop ครับ เพราะ echo '<meta http-equiv="refresh" content="2;url=view_album.php">'; มันจะ redirect ไปหน้าอื่นเลยเมื่อบันทึกข้อมูลแรกสำเร็จ Code
 
  if($rc){  
echo "บันทุึกข้อมูลเรียบร้อยแล้วครับ"; 
	 echo '<meta http-equiv="refresh" content="2;url=view_album.php">';
} else { 
echo "ไม่สามารถบันทึกข้อมูลได้ครับ";
 } 
 
 
 Code (PHP)
 
 <?php 
 include("class_dethai.php");
include ("class.imagesize.php"); 
include("conn.php");
$ID_album=$_POST[ID_album]; 
$name =$_POST[txtname];
$detail=$_POST[txtdetail];
$date1=$_POST[datepicker];
if(isset($_POST['Submit'] )) 
{ 
    $num_file = count($_FILES['file']['name']); 
    $select = false; 
    $count = 0; 
    for($i = 0; $i < $num_file ; $i++) //เนื่องจาก upload แบบ array เราจึงใช้ loop จัดการทีละไฟล์ 
    { 
        if($_FILES['file']['error'][$i] != 0) //ถ้าเกิดข้อผิดพลาดให้ข้ามไฟล์นนี้ไป 
        { 
            $count++; 
            continue; 
        } 
        if($_FILES['file']['name'][$i] != "") 
        { 
            $Filename = $_FILES['file']['name'][$i]; 
            $type = $_FILES['file']['type'][$i]; 
              //เก็บชื่อไฟล์เป็นเวลาขณะที่ upload แล้วตามด้วยนามสกุลไฟล์ ถ้าไฟล์มีชื่อเหมือนกันจะได้ไม่มีปัญหา 
          //สามารถ upload ไฟล์นามสกุล .gif, .png, .jpg, .zip, .docx, .pdf, .doc, .swf, .rar ได้ 
            $time = time() * microtime(); 
            if ( $type == "image/gif" ) {$Filename = $time.".gif"; $pic_type = 'GIF'; } 
            else if ( $type == "image/png" ) {$Filename = $time.".png"; $pic_type = 'PNG'; } 
            else if (( $type == "image/jpg") or ($type=="image/jpeg") or ($type == "image/pjpeg")){$Filename= $time.".jpg"; $pic_type = 'JPG'; } 
            else if ($type == "application/octet-stream" ) {$Filename = $time.".zip"; $pic_type = false;} 
            else if ($type == "application/vnd.openxmlformats-icedocument.wordprocessingml.document" ) {$Filename = $time.".docx"; $pic_type = false;} 
            else if ($type == "application/pdf" ) {$Filename = $time.".pdf"; $pic_type = false;} 
            else if ($type == "application/msword" ) {$Filename = $time.".doc"; $pic_type = false;} 
            else if ($type == "application/x-shockwave-flash" ) {$Filename = $time.".swf"; $pic_type = e;} 
            else if ($type == "application/octet-stream" ) {$Filename = $time.".rar"; $pic_type = false;} 
            //move ไฟล์ไปยังโฟลเดอร์ที่สร้างไว้ในที่นี้คือ fileupload 
            if(move_uploaded_file($_FILES['file']['tmp_name'][$i], 'gallery/'.$Filename)){ 
            //โค้ดในส่วนของการลดขนาดไฟล์รูปภาพ 
                if($pic_type){ 
                    $original_image = "gallery/" . $Filename ;  
                    $size = getimagesize($original_image); //ดึงขนาดของไฟล์ภาพมา 
                    $desired_height = 500 ; 
                    $desired_width = round($desired_height*$size[0]/$size[1]);
                    $image = new hft_image($original_image); 
                    $image->resize($desired_width, $desired_height, '0'); 
                    $image->output_resized("gallery/".$Filename, "JPG"); 
                } 
                //จัดเก็บชื่อไฟล์ลงฐานข้อมูล 
$sql = "INSERT INTO picture (ID_album,GalleryShot) VALUES ('$ID_album','{$Filename}');";
$rc = mysql_query($sql);
            } 
        }else{ 
            $count++; 
        } 
    } 
echo "บันทุึกข้อมูลเรียบร้อยแล้วครับ"; 
echo '<meta http-equiv="refresh" content="2;url=view_album.php">';
}else{ 
    echo "คุณยังไม่ได้เลือกไฟล์ Upload"; 
} 
?>
 |  
              | 
 ประวัติการแก้ไข
 2015-12-07 17:37:38
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-07 17:36:41 | By :
                            arm8957 |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ทดสอบแล้วครับ ภาพเมื่อทำการ save แล้ว ภาพแสดงทั้งหมดครับ แต่ข้อความและรายละเอียดไม่มาด้วยครับ ไม่รู้ติดตรงไหน ข้อความขึ้นว่า Array  เช็คใน ฐานข้อมูล php myadmin ก็ขึ้น Array เหมือนกันครับ  จะต้องแก้ไขอย่างไรครับ ไฟล์ save อยู่ด้านบนกระทู้ครับ 
 
  
 
  
 
  
 gallery_list  Code (PHP)
 
  <td>
<?
			  include ("class_dethai.php"); 
include("conn.php");
		$sql = "SELECT * FROM album WHERE ID_album = '".$_GET["ID_album"]."' ";
		$query = mysql_query($sql) or die ("Error Query [".$sql."]");
		$result = mysql_fetch_array($query);
?>
              </p>
			    <p><?php echo $result["ID_album"];?><br />
  <img src="myfile/<?php echo $result["Picture_pic"];?>" width="180" height="120" /></p></td>
            </tr>
            <tr>
              <td width="249" align="right">ชื่ออัลบั้ม</td>
              <td width="776">          
                <?=$result["Name_pic"];?></td>
            </tr>
            <tr>
              <td align="right">รายละเอียด</td>
              <td>               
                <?=$result["Detail_pic"];?></td>
            </tr>
            <tr>
              <td align="right">วันที่</td>
              <td>           
                <? $strDate = $result["Date_pic"];
     echo DateThai($strDate);?></td>
            </tr>
            <tr>
              <td colspan="2" align="right"> </td>
            </tr>
            <tr>
              <td colspan="2"><?
		$sql2 = "SELECT * FROM picture WHERE ID_album = '".$_GET["ID_album"]."' ORDER BY ID_album ASC ";
		$query2 = mysql_query($sql2) or die ("Error Query [".$sql2."]");
		echo"<table border=\"0\"  cellspacing=\"0\" cellpadding=\"0\"  align=\"center\" ><tr>";
		$intRows = 0;
		while($result2 = mysql_fetch_array($query2))
		{
			echo "<td>"; 
			$intRows++;
	?>
                <table width="245"  height="170" border="0" align="center" cellpadding="0" cellspacing="0">
                  <tr>
                    <td align="center"><p><a href="gallery/<?=$result2["GalleryShot"];?>" rel="lightbox[roadtrip]" 
        title="<?=$result2["GalleryShot"];?>"><img src="gallery/<?=$result2["GalleryShot"];?>" alt="" width="150" height="100" /></a>
         <a href="gallery_delete.php?ID_pic=<?=$result2["ID_pic"]; echo "&ID_album=",$_GET["ID_album"];?>" onclick="return confirm('คุณต้องการที่จะลบข้อมูลหรือไม่')">ลบ</a>
                      <?=$result2["GalleryShot"];?>
                      <br />
                      <?=$result2["Detail_img"];?>
                      <br />
                    <? $strDate = $result2["Date_img"];
     echo DateThai($strDate);?>
                    </p></td>
                  </tr>
                </table>
                <?
			echo"</td>";
			if(($intRows)%3==0)
			{
				echo"</tr>";
			}
		}
		echo"</tr></table>";
		mysql_close();
	?></td>
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-08 14:16:03 | By :
                            godzaa |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (PHP) 
 <?php 
 include("class_dethai.php");
include ("class.imagesize.php"); 
include("conn.php");
$ID_album=$_POST[ID_album]; 
$name =$_POST[txtname];
$detail=$_POST[txtdetail];
$date1=$_POST[datepicker];
if(isset($_POST['Submit'] )) 
{ 
    $num_file = count($_FILES['file']['name']); 
    $select = false; 
    $count = 0; 
    for($i = 0; $i < $num_file ; $i++) //เนื่องจาก upload แบบ array เราจึงใช้ loop จัดการทีละไฟล์ 
    { 
        if($_FILES['file']['error'][$i] != 0) //ถ้าเกิดข้อผิดพลาดให้ข้ามไฟล์นนี้ไป 
        { 
            $count++; 
            continue; 
        } 
        if($_FILES['file']['name'][$i] != "") 
        { 
            $Filename = $_FILES['file']['name'][$i]; 
            $type = $_FILES['file']['type'][$i]; 
              //เก็บชื่อไฟล์เป็นเวลาขณะที่ upload แล้วตามด้วยนามสกุลไฟล์ ถ้าไฟล์มีชื่อเหมือนกันจะได้ไม่มีปัญหา 
          //สามารถ upload ไฟล์นามสกุล .gif, .png, .jpg, .zip, .docx, .pdf, .doc, .swf, .rar ได้ 
            $time = time() * microtime(); 
            if ( $type == "image/gif" ) {$Filename = $time.".gif"; $pic_type = 'GIF'; } 
            else if ( $type == "image/png" ) {$Filename = $time.".png"; $pic_type = 'PNG'; } 
            else if (( $type == "image/jpg") or ($type=="image/jpeg") or ($type == "image/pjpeg")){$Filename= $time.".jpg"; $pic_type = 'JPG'; } 
            else if ($type == "application/octet-stream" ) {$Filename = $time.".zip"; $pic_type = false;} 
            else if ($type == "application/vnd.openxmlformats-icedocument.wordprocessingml.document" ) {$Filename = $time.".docx"; $pic_type = false;} 
            else if ($type == "application/pdf" ) {$Filename = $time.".pdf"; $pic_type = false;} 
            else if ($type == "application/msword" ) {$Filename = $time.".doc"; $pic_type = false;} 
            else if ($type == "application/x-shockwave-flash" ) {$Filename = $time.".swf"; $pic_type = e;} 
            else if ($type == "application/octet-stream" ) {$Filename = $time.".rar"; $pic_type = false;} 
            //move ไฟล์ไปยังโฟลเดอร์ที่สร้างไว้ในที่นี้คือ fileupload 
            if(move_uploaded_file($_FILES['file']['tmp_name'][$i], 'gallery/'.$Filename)){ 
            //โค้ดในส่วนของการลดขนาดไฟล์รูปภาพ 
                if($pic_type){ 
                    $original_image = "gallery/" . $Filename ;  
                    $size = getimagesize($original_image); //ดึงขนาดของไฟล์ภาพมา 
                    $desired_height = 500 ; 
                    $desired_width = round($desired_height*$size[0]/$size[1]);
                    $image = new hft_image($original_image); 
                    $image->resize($desired_width, $desired_height, '0'); 
                    $image->output_resized("gallery/".$Filename, "JPG"); 
                } 
                //จัดเก็บชื่อไฟล์ลงฐานข้อมูล 
$sql = "INSERT INTO picture (ID_album,GalleryName,GalleryShot,Detail_img,Date_img) VALUES ('$ID_album','$name ','{$Filename}','$detail','$date1');";
$rc = mysql_query($sql);
		 } 
        }else{ 
            $count++; 
        } 
    } 
echo "บันทุึกข้อมูลเรียบร้อยแล้วครับ"; 
echo '<meta http-equiv="refresh" content="2;url=view_album.php">';
}else{ 
    echo "คุณยังไม่ได้เลือกไฟล์ Upload"; 
} 
?>
 ลองรับค่ามาแล้วครับ ก็ยังขึ้น ค่า Array ครับ มีวิธิไหนที่ช่วยได้ครับ
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-20 10:56:13 | By :
                            godzaa |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |