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 > ขอคำแนะนำหน่อยครับ เรื่องการ preview รูปก่อน upload หลายๆรูปครับ



 

ขอคำแนะนำหน่อยครับ เรื่องการ preview รูปก่อน upload หลายๆรูปครับ

 



Topic : 122144



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



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




ที่ผมทำคือเวลาเลือกไฟล์รูปแล้วให้มันแสดงรูปที่เลือกขึ้นมาในช่อง ตัวอย่างภาพอะครับ
ผมเอามาจาก https://www.thaicreate.com/tutorial/javascript-display-preview-images-before-upload.html
แต่มีปัญหาตรงเวลาจะอัพโหลดรูปมากกว่า 1 รูปมันจะขึ้นรูปแทนที่รูปเก่าที่ช่องเดิมอะครับ ทำยังไงให้มันไม่ไปแทนที่กันครับ

prepic

Code (PHP)
<center>
        <br/>
        <br/>
          <table width="70%" border="2px" id="tbExp" border-color:#c0c0c0 >
          <tr style="background: #0cadbe; color:#ffffff";>
            <td><div align="center"><label>รูปที่</div></td>
            <td><div align="center"><label>คำอธิบาย</label></div></td>
            <td><div align="center"><label>รูปภาพ</label></div></td>
            <td><div align="center"><label>ตัวอย่างภาพ</label></div></td>
            </tr>
          </table>
        <br/>

        <input type="hidden" name="hdnMaxLine" value="0">
          <button name="btnAdd" type="button" id="btnAdd" class="buton b_green-1 buton-4 buton-mini" onClick="CreateNewRow();">+</button>
          <button name="btnDel" type="button" id="btnDel" class="buton b_red buton-4 buton-mini" onClick="RemoveRow();">-</button>

              <br/><br/>

        </center>


Code (JavaScript)
<script language="JavaScript">
          function showPreview(ele)
            {
              var intLine = parseInt(document.frmMain.hdnMaxLine.value);
              intLine++;
              $('#imgAvatar').attr('src', ele.value); // for IE
                if (ele.files && ele.files[0]) {
            
                var reader = new FileReader();
                
                reader.onload = function (e) {
                    $('#imgAvatar').attr('src', e.target.result);
                }

                reader.readAsDataURL(ele.files[0]);
              }
            }
        </script>
        


        <script type="text/javascript">

        function CreateNewRow()
        {
          var intLine = parseInt(document.frmMain.hdnMaxLine.value);
          intLine++;
      
          var theTable = document.all.tbExp
          var newRow = theTable.insertRow(theTable.rows.length)
          newRow.id = newRow.uniqueID
    
          var item1 = 1
          var newCell
    
          //*** Column 1 ***//
          newCell = newRow.insertCell(0)
          newCell.id = newCell.uniqueID
          newCell.setAttribute("className", "css-name");
          newCell.innerHTML = "<center>"+intLine+"</center>"



          //*** Column 2 ***//
          newCell = newRow.insertCell(1)
          newCell.id = newCell.uniqueID
          newCell.setAttribute("className", "css-name");
          newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" size=\"60\" class=\"form-control input-sm\" style=\"width:100%\" NAME=\"Column2_"+intLine+"\" VALUE=\"\"></center>"   
    
          //*** Column 3 ***//
          newCell = newRow.insertCell(2)
          newCell.id = newCell.uniqueID
          newCell.setAttribute("className", "css-name");
          newCell.innerHTML = "<center><input type=\"file\" name=\"filUpload"+intLine+"\" id=\"file_upload\" OnChange=\"showPreview(this)\"></center>" 

          //*** Column 4 ***//
          newCell = newRow.insertCell(3)
          newCell.id = newCell.uniqueID
          newCell.setAttribute("className", "css-name");
          newCell.innerHTML = "<center><img id=\"imgAvatar\" width=\"100\" height=\"100\"></img></center>"    
    
          document.frmMain.hdnMaxLine.value = intLine;
        }
  
        function RemoveRow()
        {
          intLine = parseInt(document.frmMain.hdnMaxLine.value);
          if(parseInt(intLine) > 0)
          {
            theTable = (document.all) ? document.all.tbExp : 
            document.getElementById("tbExp")
            theTableBody = theTable.tBodies[0];
            theTableBody.deleteRow(intLine);
            intLine--;
            document.frmMain.hdnMaxLine.value = intLine;
          } 
        } 

      //////////////////////////
      </script>




Tag : PHP, HTML/CSS, JavaScript









ประวัติการแก้ไข
2016-03-27 03:27:43
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-03-27 03:26:54 By : sonicpola View : 943 Reply : 3
 

 

No. 1



โพสกระทู้ ( 9,556 )
บทความ ( 2 )



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


function showPreview(ele, idx)
$('#imgAvatar'+idx).attr('src', ele.value);
....
....
$('#imgAvatar'+idx).attr('src', e.target.result);
....
....
newCell.innerHTML = "<center><input type=\"file\" name=\"filUpload"+intLine+"\" id=\"file_upload\" OnChange=\"showPreview(this, "+intLine+")\"></center>"
...
...
newCell.innerHTML = "<center><img id=\"imgAvatar"+intLine+"\" width=\"100\" height=\"100\"></img></center>"






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-03-27 06:40:50 By : Chaidhanan
 


 

No. 2



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



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


ตอบความคิดเห็นที่ : 1 เขียนโดย : Chaidhanan เมื่อวันที่ 2016-03-27 06:40:50
รายละเอียดของการตอบ ::
ได้แล้วครับบ ขอบคุณมากๆครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-03-27 11:17:04 By : sonicpola
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-03-27 19:54:59 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ขอคำแนะนำหน่อยครับ เรื่องการ preview รูปก่อน upload หลายๆรูปครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 05
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 อัตราราคา คลิกที่นี่