<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text/css"> #ttt { text-align: right; } </style> </head> <? mysql_connect("localhost","root","root"); mysql_select_db("project"); $strSQL = "SELECT * FROM album"; $objQuery = mysql_query($strSQL); ?> <script language="javascript"> function CreateSelectOption(ele) { var objSelect = document.getElementById(ele); var Item = new Option("", ""); objSelect.options[objSelect.length] = Item; <? while($objResult = mysql_fetch_array($objQuery)) { ?> var Item = new Option("<?=$objResult["album_name"];?>", "<?=$objResult["id_album"];?>"); objSelect.options[objSelect.length] = Item; <? } ?> } function CreateNewRow() { var intLine = parseInt(document.frmMain.hdnMaxLine.value); intLine++; var theTable = document.getElementById("tbExp"); var newRow = theTable.insertRow(theTable.rows.length) newRow.id = newRow.uniqueID var newCell //*** Column 1 ***// newCell = newRow.insertCell(0); newCell.id = newCell.uniqueID; newCell.setAttribute("className", "css-name"); newCell.innerHTML = "<center><INPUT TYPE=\"file\" SIZE=\"5\" NAME=\"filUpload"+intLine+"\" ID=\"filUpload"+intLine+"\" VALUE=\"\"></center>"; document.frmMain.hdnMaxLine.value = intLine; } function RemoveRow() { intLine = parseInt(document.frmMain.hdnMaxLine.value); if(parseInt(intLine) > 0) { theTable = document.getElementById("tbExp"); theTableBody = theTable.tBodies[0]; theTableBody.deleteRow(intLine); intLine--; document.frmMain.hdnMaxLine.value = intLine; } } </script> <body> <form name="frmMain" method="post" action="add_image.php"> <table width="445" border="0" id="tbExp"> <tr> <td><div align="center">เลือกไฟล์ <input name="btnAdd" type="button" id="btnAdd" value="เพิ่ม +" onClick="CreateNewRow();"> <input name="btnDel" type="button" id="btnDel" value="ลบ -" onClick="RemoveRow();"> </div></td> </tr> </table> <p> <input type="hidden" name="hdnMaxLine" value="0"> <input name="input" type="submit" value="ยืนยัน" > </p> </form> </body> </html>
<html> <head> <title>ThaiCreate.Com Tutorial</title> </head> <body> <? $objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database"); $objDB = mysql_select_db("project"); for($i=0;$i<count($_FILES["filUpload"]["name_photo"]);$i++) { if($_FILES["filUpload"]["name_photo"][$i] != "") { if(move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"myfile/".$_FILES["filUpload"]["name_photo"][$i])) { //*** Insert Record ***// $strSQL = "INSERT INTO photo "; $strSQL .="(name_photo) VALUES ('".$_FILES["filUpload"]["name_photo"][$i]."')"; $objQuery = mysql_query($strSQL); } } } echo "Copy/Upload Complete<br>"; ?> <a href="PageMultiUploadToMySQL3.php">View files</a> </body> </html>
//*** Insert Record ***// $strSQL = "INSERT INTO photo "; $strSQL .="(name_photo) VALUES ('".$_FILES["filUpload"]["name_photo"][$i]."')"; $objQuery = mysql_query($strSQL); echo $strSQL;
Quote: for($i=0;$i<count($_FILES["filUpload"]["name_photo"]);$i++) {
for($i=0;$i<count($_POST["hdnMaxLine"]);$i++) {
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง