ช่วยแนะนำทีครับ!!!! อัพโหลดรูปลงฐานข้อมูลทีละหลายรูปยังไง

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

ช่วยแนะนำทีครับ!!!! อัพโหลดรูปลงฐานข้อมูลทีละหลายรูปยังไง
ช่วยแนะนำทีครับ คือ แบบว่าทำโปรเจคเรื่องเกี่ยวกับระบบฝากขายรถมอเตอร์ไซค์ แต่ติดที่ว่า ไม่รู้ว่าอัพโหลดทีละหลายรูปยังไง ถามอาจารย์ อาจารย์บอกว่า แบบอาร์เรย์ และอีกอย่างไม่รุว่า ชนิดของข้อมูลด้วย ช่วยหน่อยครับ


Newnot 1.10.249.xxx 22-11-2014 10:52:53

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

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


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


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

 ความคิดเห็นที่ 1
ลองดูจากคำถามนี้ เป็นแนวทาง

https://www.ninenik.com/forum_view_1116_1.html

หรือใช้วิธีนี้เป็นแนวทาง
สร้างไฟล์ แบบเลือกอัพรูปได้หลายๆ รูปพร้อมกัน 

แสดงตัวอย่าง รูปภาพ ก่อนอัพโหลด ด้วย html5 อย่างง่าย 
https://www.ninenik.com/content.php?arti_id=551 via @ninenik

ไฟล์ ตัวอย่าง test_uppic_multi.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<!--    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">-->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <style type="text/css">
        .drop-area{
          width:100px; height:25px;
          border: 1px solid #999; text-align: center;
          padding:10px; cursor:pointer;
        }
        #thumbnail img{width:100px;height:100px;margin:5px;}
        canvas{border:1px solid red;}    
    </style>
</head>
<body>

    <br>  
    <div style="margin:auto;width:80%;">  
        <h3> บันทึกข้อมูล</h3>   
        <form class="form" id="myFrom" method="post" action="uppic_multi.php"  role="form" enctype="multipart/form-data">    
            <div class="form-group">  
               <lable class="control-label">Name : </lable>  
                <input type="text" autocomplete="off" class="form-control" name="name">  
            </div>  
            <div class="form-group">  
               <lable class="control-label">Picture : </lable>  
               <input id="file_upload" style="display:none" name="file_upload[]" type="file" multiple="true">  
            <div id="upload" class="btn btn-info">
               Upload File
            </div>
            <div id="thumbnail"></div>               
            </div>  
            <button type="submit"  class="btn btn-primary">เพิ่มข้อมูล</button>             
        </form>  
        <br>  
        
    </div>


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>  
<script type="text/javascript" >
$(function () {


    $("#upload").on("click",function(e){
        $("#file_upload").show().click().hide();
        e.preventDefault();
    });
    $("#file_upload").on("change",function(e){
        var files = this.files
        showThumbnail(files)        
    });

    function showThumbnail(files){

        $("#thumbnail").html("");
        for(var i=0;i<files.length;i  ){
            var file = files[i]
            var imageType = /image.*/
            if(!file.type.match(imageType)){
                //     console.log("Not an Image");
                continue;
            }

            var image = document.createElement("img");
            var thumbnail = document.getElementById("thumbnail");
            image.file = file;
            thumbnail.appendChild(image)

            var reader = new FileReader()
            reader.onload = (function(aImg){
                return function(e){
                    aImg.src = e.target.result;
                };
            }(image))

            var ret = reader.readAsDataURL(file);
            var canvas = document.createElement("canvas");
            ctx = canvas.getContext("2d");
            image.onload= function(){
                ctx.drawImage(image,100,100)
            }
        } // end for loop

    } // end showThumbnail


    
    
});
 </script>    
</body>
</html>



ไฟล์รับค่าที่ส่งมา และทำการอัพโหลดรูป uppic_multi.php

<?php
header("Content-type:text/html; charset=UTF-8");              
header("Cache-Control: no-store, no-cache, must-revalidate");             
header("Cache-Control: post-check=0, pre-check=0", false);   
//// BEGIN UPPIC FUNCTION
function uppic_only($img,$index,$imglocate,$limit_size=2000000,$limit_width=0,$limit_height=0){
	$allowed_types=array("jpg","jpeg","gif","png");   
	if($img["name"][$index]!=""){
		$fileupload1=$img["tmp_name"][$index];
		$data_Img=@getimagesize($fileupload1);
		$g_img=explode(".",$img["name"][$index]);
		$ext = strtolower(array_pop($g_img));  
		$file_up=time()."-".$index.".".$ext;		
		$canUpload=0;
		if(isset($data_Img) && $data_Img[0]>0 && $data_Img[1]>0){
			if($img["size"][$index]<=$limit_size){				
				if($limit_width>0 && $limit_height>0){
					if($data_Img[0]<=$limit_width && $data_Img[1]<=$limit_height){
						$canUpload=1;
					}					
				}elseif($limit_width>0 && $limit_height==0){
					if($data_Img[0]<=$limit_width){
						$canUpload=1;
					}		
				}elseif($limit_width==0 && $limit_height>0){
					if($data_Img[1]<=$limit_height){
						$canUpload=1;
					}												
				}else{
					$canUpload=1;					
				}			
			}else{

			}			
		}		
		if($fileupload1!="" && @in_array($ext,$allowed_types) && $canUpload==1){			
				@copy($fileupload1,$imglocate.$file_up);	
				@chmod($imglocate.$file_up,0777);								
		}else{
			$file_up="";
		}
	}
	return $file_up; // ส่งกลับชื่อไฟล์
}
//////  END UPPIC FUNCTION


$num_pic=count($_FILES['file_upload']['name']);  // นับว่ามีการส่งรูปภาพมาเพื่ออัพหรือไม่
if($num_pic>0 && $_FILES['file_upload']['name'][0]!=""){ // ถ้ามีอย่างน้อยหนึ่งรูป
   for($i=0;$i<$num_pic;$i++){  // วนลูปอัพรูป
       $upfile_name=uppic_only($_FILES['file_upload'],$i,"uppic/");  // อัพรูปไปไว้ที่โหลเดอร์ uppic
       echo $upfile_name."<br>";  // จะได้ชื่อไฟล์รูป ที่อัพเสร็จแล้วมาใช้งาน
       // วนลูปคำสั่งบันทึกลงฐานข้อมูลหรืออื่นๆ ตามต้องการ
   }
}
?>


ซึ่งดัดแปลงเล็กน้อยจากเนื้อหา

สร้างฟังก์ชันสำหรับอัพโหลดรูป แบบกำหนดเงื่อนไข อย่างง่าย 


ninenik 1.46.17.xxx 22-11-2014
 ความคิดเห็นที่ 2
แล้วถ้า insert ลง database mysql ต้องเพิ่มส่วนไหนบ้างอ่ะครับ


kooppee0 171.7.8.xxx 10-05-2018 21:20
 ความคิดเห็นที่ 3


Pichet Chuenchom 171.7.232.xxx 16-07-2019 16:57
1






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