 |
|
ต้องเอาส่วนนี้ที่ 1 ไปอยู่ตรงไหนของส่วนที่ 2 คะ
ตรงส่วนนี้
function plus(){
if (n>=5){
return;
}
if (w==1) { plusnormal(); }
if (w==2 && n<5){ plusremote(); }
}
*** ถ้าเกิน 5 ช่องแล้วให้ขึ้น alert เตือนว่า ครบจำนวน 5 ช่องแล้ว ต้องเพิ่มยังไงคะ
ส่วนที่ 1
Code (PHP)
<?php
function extIs($file_name,$ext){
$file_ext=strtolower(substr(strrchr($file_name,'.'),1));
return in_array($file_ext,$ext,true);
}
$EXT = array('jpg','jpeg');
$MAX_SIZE = 2*1024*1024; //2M
$err = '';
foreach($_FILES as $name => $file){
if ($file['size']>$MAX_SIZE){
$err .= "\nFILE SIZE ERROR";
}
if (!extIs($file['name'],$EXT)){
$err .= "\nFILE EXTENSION ERROR";
}
}
if (empty($err)){
echo 'no error';
}else{
echo 'has error:',nl2br($err);
}
?>
ส่วนที่ 2
<?php
$host="localhost";
$username = "";
$password = "";
$db="photo";
$connect=mysql_connect($host,$username,$password) or die ("Cannot Connect to MySQL");
mysql_select_db($db,$connect) or die ("Cannot connect to Database");
if($_POST['add']==1){
foreach($_FILES as $name => $file){
//echo 'input = '.$name.', file = '.$file['name'].', tmp_name = '.$file['tmp_name'].'<br>';
$path = "uppic/"; //ตำแหน่งของโฟลเดอร์ ที่ต้องการเก็บไฟล์
move_uploaded_file($file['tmp_name'],$path.$file['name']);
// mysql_query("insert into tb_name () values () ");
//$file_name = $file['tmp_name'];
$file_name = $file['name'];
mysql_query("INSERT INTO mypic (id, files) values('', '$file_name')") or die ("Cannot Add Database");
}
}
?>
<HTML>
<HEAD>
<TITLE>upload</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-874">
</HEAD>
<BODY>
<FORM name="F1" onSubmit="" action="<?=$PHP_SELF;?>"
method="post" encType="multipart/form-data">
<INPUT type="hidden" name="add" id="add" value="1">
<SCRIPT language="javascript" type="text/javascript">
var n = 1;
var w = 1;
function mknormal(){
w = 1;
n = 1;
document.getElementById("tx").innerHTML= '<input name="file1" type="file" /><br />';
//document.F1.action = "";
}
function plus(){
if (w==1) { plusnormal(); }
if (w==2 && n<5){ plusremote(); }
}
function plusremote() {
n = n+1;
var main = document.getElementById("tx");
document.getElementById("dasminus").style.visibility='visible';
document.getElementById("dasminus").style.fontSize='20px';
var newnode = document.createElement("input");
newnode.type="text";
newnode.name="link";
main.appendChild(newnode);
main.appendChild(document.createElement("br"));
}
function plusnormal() {
n = n+1;
document.getElementById("dasminus").style.visibility='visible';
document.getElementById("dasminus").style.fontSize='20px';
var main = document.getElementById("tx");
var newnode = document.createElement("input");
newnode.type="file";
newnode.name="file"+n;
main.appendChild(newnode);
main.appendChild(document.createElement("br"));
}
function minus() {
if (n>1) {
n = n-1;
var main = document.getElementById("tx");
main.removeChild(main.lastChild);
main.removeChild(main.lastChild);
}
if (n==1){
document.getElementById("dasminus").style.visibility='hidden';
document.getElementById("dasminus").style.fontSize='1px';
}
}
</SCRIPT>
<TABLE width="58%" border="0" style="MARGIN-BOTTOM: 0px">
<TBODY>
<TR>
<TD width="50" align="center" valign="top">
<A href="javascript:plus();" style="color:#009900; font-size:20px;
font-weight:bold; text-decoration:none;">+ </A>
</TD>
<TD width="705" rowSpan="2" valign="top">
<DIV id="tx"><!--<script language="javascript">mknormal();</script>-->
<input name="file" type="file" /><br /></DIV>
</TD>
</TR>
<TR>
<TD align="center" valign="bottom">
<DIV id="dasminus" style="visibility:hidden;">
<A style="color:#FF0000; font-size:20px; font-weight:bold;
text-decoration:none;" href="javascript:minus();">- </A>
</DIV>
</TD>
</TR>
</TBODY>
</TABLE>
<input name="submit" type="submit" value="upload...">
<input name="reset" type="button" value="refresh" onClick="window.location.href='upload.php';">
</FORM>
</BODY>
</HTML>
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2009-08-30 12:18:05 |
By :
gigza |
View :
1017 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |