|
|
|
[javascript] ขอด่วนมาก!!! เรื่อง อัพโหลดไฟล์ โดยไม่ใช้ input file อะครับ ใช้ javascript เหมือน jquery plugin หลายๆตัวที่เขาทำกัน... |
|
|
|
|
|
|
|
ช่วยตอบด้วยคราบบบ
|
|
|
|
|
Date :
2013-04-10 21:56:53 |
By :
phoomin2012 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันใช้ประมาณนี้ครับ
JavaScript Input type file: Changing browse button
เค้าอาาจจะใช้การซ่อนเอาไว้ครับ
|
|
|
|
|
Date :
2013-04-11 06:27:35 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากเลยครับ
|
|
|
|
|
Date :
2013-04-11 11:06:24 |
By :
phoomin2012 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมลองเอาไปดัดแปลงในเว็บผมแต่มันก็ไม่ได้อะครับ
Edit.php : Code (PHP)
<?
$q = mysql_query("SELECT * FROM `".PRE."user` WHERE `uid`='".$uid."'");
$user = mysql_fetch_array($q);
$you = $_POST['status'];
$yuid = $_POST['yuid'];
if(empty($user['img'])){
$img = "image.php?id=13";
}else{
$img = "image.php?id=".$user['img'];
}
if($user['status']==BAN){
$status = '<font color="#FF0000">ถูกแบน</font>';
}elseif($user['status']==USER){
$status = '<font color="#000000">ผู้ใช้ธรรมดา</font>';
}elseif($user['status']==ADMIN){
$status = '<font color="#00CCCC">แอดมิน</font>';
}
?>
<div class="hero-unit">
<form action="function_new/insert_img_user.php" method="post" name="formimguser" target="iframe_target" enctype="multipart/form-data" onSubmit="return ChkSubmit();">
<iframe id="iframe_target" name="iframe_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
<script language="JavaScript">
function ChkSubmit(result)
{
if(document.getElementByName("imguser").value == "")
{
alert('Please select file...');
return false;
}
document.getElementById("divresult").innerHTML ="Uploading....";
return true;
}
function showResult(result)
{
if(result==1)
{
document.getElementById("divresult").innerHTML = "<font color=green> Save successfully! </font> <br>";
}
else
{
document.getElementById("divresult").innerHTML = "<font color=red> Error!! Cannot upload data </font> <br>";
}
}
</script>
<input type="file" name="imguser" style="display: none;">
<input type="hidden" name="name" value="<?=$user['username'];?>" />
<h1><a href="#" onClick="imguser.click();show_part_img.value=imguser.value;"><img src="<?=$img;?>" width="140" height="140" /></a> <?=$user['username'];?></h1><br />
<div><input type="submit" value="show_part_img" /></div><div id="divresult"></div>
</form>
<form action="" method="post" name="formedit" id="formedit">
<table class="table table-striped">
<tr>
<td width="190">User ID</td><td><?=$uid;?><input type="hidden" value="<?=$uid;?>" /></td>
</tr>
<tr>
<td>Username</td><td><?=$user['username'];?><input type="hidden" value="<?=$user['username'];?>" /></td>
</tr>
<tr>
<td>สถานะ</td><td><?=$status;?><input type="hidden" value="<?=$user['status'];?>" /></td>
</tr>
<tr>
<td>Coin</td><td><?=$user['coin'];?></td>
</tr>
<tr>
<td>ชื่อจริง</td><td><input type="text" value="<?=$user['name'];?>" /></td>
</tr>
<tr>
<td>นามสกุลจริง</td><td><input type="text" value="<?=$user['lastname'];?>" /></td>
</tr>
<tr>
<td>เพศ</td><td><input type="text" value="<?=$user['male'];?>" /></td>
</tr>
<tr>
<td>วันเกิด</td><td><input type="text" value="<?=$user['birthday'];?>" /></td>
</tr>
<tr>
<td colspan="2" align="center"><center>ตัวเลือก</center></td>
</tr>
<tr>
<td colspan="2" align="center"><center>
<button type="submit" class="btn">บันทึก</button>
</center></td>
</tr>
</table>
</form>
</div>
insert_img_user.php : Code (PHP)
<?
$name = $_POST['name'];
$fp = fopen($_FILES["imguser"]["tmp_name"],"r");
$ReadBinary = fread($fp,filesize($_FILES["imguser"]["tmp_name"]));
fclose($fp);
$FileData = addslashes($ReadBinary);
$q = mysql_query("SELECT * FROM ".PRE."user WHERE username='".$name."'");
if(mysql_query("INSERT INTO `".PRE."images` (`pid`, `name`, `img`, `detail`) VALUES (NULL, 'รูปภาพของ ".$name."', '".$FileData."', 'รูปภาพของ ".$name."');"))
{
$q = mysql_query("SELECT * FROM images WHERE name='รูปภาพของ ".$name."'");
$img_user = mysql_fetch_array($q);
$sql = "UPDATE `".PRE."user` SET `img`='".$img_user['pid']."' WHERE `username`=".$name.";";
mysql_query($sql);
echo "<script>alert('Upload file successfully!');</script>";
echo "<script>window.top.window.showResult('1');</script>";
}
else
{
echo "<script>alert('Error! Cannot upload data');</script>";
echo "<script>window.top.window.showResult('2');</script>";
}
?>
|
|
|
|
|
Date :
2013-04-12 11:28:18 |
By :
phoomin2012 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|