|
|
|
PHP - ต้องการเพิ่มช่อง Add File แบบ Dynamic โดยการคลิกที่เพิ่มไฟล์อัพโหลด (Upload) |
|
|
|
|
|
|
|
Code (PHP)
<script src="http://code.jquery.com/jquery-1.8.3.js "></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<input type="file" name="uploadfiles[]" /> <span id="moreUpload">เพิ่มไฟล์อัพโหลด</span><br />
<div id="uploadframe"></div>
<script>
$(document).ready(function(){
var uploadString = '<input type="file" name="uploadfiles[]" /><br />';
$("#moreUpload").click(function(){
$("#uploadframe").append(uploadString);
});
});
</script>
|
|
|
|
|
Date :
2013-08-29 15:12:08 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<style type="text/css">
#imageUpload input {
display: block;
}
</style>
<script type="text/javascript">
// Created by: ctr.........
function fileFields() {
var x = document.getElementById('imageUpload');
x.onclick = function() {
var i = parseFloat(this.lastChild.id)+1;
input = document.createElement("input");
input.setAttribute("type", "file");
input.setAttribute("name", 'imageName_' + i);
input.setAttribute("id", i);
this.appendChild(input);
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
fileFields();
});
</script>
<a href="#" id="imageUpload"><input type="file" name="imageName_1" id="1" /></a>
|
|
|
|
|
Date :
2013-08-29 15:15:28 |
By :
gest |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูครับ
Ajax CreateElement
|
|
|
|
|
Date :
2013-08-29 20:30:15 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2013-08-30 06:26:07 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
สำหรับไฟล์ php
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
for($i=0;$i<count($_FILES["filUpload"]["name"]);$i++)
{
if($_FILES["filUpload"]["name"][$i] != "")
{
if(move_uploaded_file($_FILES["filUpload"]["tmp_name"][$i],"myfile/".$_FILES["filUpload"]["name"][$i]))
{
echo "Copy/Upload Complete<br>";
}
}
}
?>
</body>
</html>
|
|
|
|
|
Date :
2013-08-30 06:27:53 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<div class="inputtype">
</div>
<input type="hidden" id="num" value="0" />
<button id="btnP">+</button>
<button id="btnD">-</button>
<script src="admin/bootstrap/js/jquery-1.10.2.min.js"></script>
<script>
$(function(){
$('#btnP').click(function(){
var num=parseInt($('#num').val())+1;
$('#num').val(num);
var file=$('<input>').attr({'type':'file','id':'img'+num,'name':'img[]'});
file.val(num);
$('.inputtype').append(file);
btn();
});
$('#btnD').click(function(){
var num=parseInt($('#num').val());
$('#img'+num).remove();
$('#num').val(num-1);
btn();
});
});
function btn(){
var num=$('#num').val();
if(num <= 1){
$('#btnD').hide();
}else{
$('#btnD').show();
}
}
</script>
|
ประวัติการแก้ไข 2013-08-30 09:44:37
|
|
|
|
Date :
2013-08-30 09:43:09 |
By :
Ex-[S]i[L]e[N]t |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|