|
|
|
ดึงรูปจากตาราง member เข้าไปเก็บที่ webboard_question ไม่ได้อ่ะค่ะ |
|
|
|
|
|
|
|
เมื่อสมาชิก login เข้ามาตั้งกระทู้ ดึงรูปของ user , username, id ของสมาชิกมาโชว์ได้แล้ว
ในหน้า AddTopicForm.php แต่ปัญหาคือว่า จะทำงัยให้เอารูป user ไปเก็บในตาราง
webboard_question ส่งไปได้แค่ username กับ id ค่ะ
ใน folder member มี subfolder ชื่อ userPic ไว้เก็บรูป user
ใน folder webboard มี subfolder ชื่อ userPic ไว้เก็บรูป user เหมือนกันค่ะ
++++++++++++++++++++++++++++++
ส่วนนี้เขียนในหน้า AddTopicForm.php นะคะ
<img src="../member/userPic/<?=$row['userPic']?>" width="<?=$w?>" height="<?=$h?>" border="0"><br>
<input type="hidden" name="userPic" value="../member/userPic/<?=$row['userPic']?>" > ไม่แน่ใจว่า รูป ส่งไปแบบ hidden ได้มั๊ยคะ
<input type="hidden" name="$_SESSION['username']" value="<?=$_SESSION['username']?>" >
<strong class="site">
<?=$_SESSION['username']?>
<br>
</strong>
<span class="site">
<input type="hidden" name="id" value="<?=$row['id']?>" >
ID : <? echo m00.$row[id]; ?> </span>
++++++++++++++++++++++++++++++
ส่วนนี้เขียนในหน้า AddTopicSave.php นะคะ
<?
session_start();
include("../connect.php");
$topic = $_POST['topic'];
$detail = $_POST['detail'];
$date = "now()";
$ip = $_SERVER['REMOTE_ADDR'];
$attach = $_FILES['attach'];
$newname = "";
$username = $_SESSION['username'];
$id = $_POST['id'];
$userPic = $_FILES['userPic']; ** userPic ที่รับมา อยู่ที่ member/userPic/file.type จะไปเก็บเป็นชื่อใหม่ใน webboard/userPic/newnamefile.type ค่ะ code ผิดมั๊ยคะ
$newnameM = "";
//รูปประกอบกระทู้ให้ attach รูปได้เฉพาะ gif หรือ jpeg
if($attach['size']>0)
{
if($attach['type']=="image/pjpeg")
{ //ถ้ารูปเป็น gif หรือ jpeg ให้ตั้งชื่อรูปตามค่าเวลาที่เพิ่มขึ้นเป็นวินาที และเอาไปเก็บไว้ใน folder attach
$newname = time().".jpg"; move_uploaded_file($attach['tmp_name'],"attach/$newname");
}else if($attach['type']=="image/gif")
{
$newname = time().".gif";
move_uploaded_file($attach['tmp_name'],"attach/$newname");
}else //ถ้ารูปไม่ใช่ gif และ jpeg ให้ฟ้อง error
{
echo "<script>alert('Upload รูปเท่านั้นคร๊าบ');history.back();</script>";
exit();
}
}
//รูปสมาชิก ให้ attach รูปได้เฉพาะ gif หรือ jpeg
if($userPic['size']>0)
{
if($userPic['type']=="image/pjpeg")
{ //เก็บไว้ใน folder userPic
$newnameM = time().".jpg";
move_uploaded_file($userPic['tmp_name'],"userPic/$newnameM");
}else if($userPic['type']=="image/gif")
{
$newnameM = time().".gif";
move_uploaded_file($userPic['tmp_name'],"userPic/$newnameM");
}else
{
echo "<script>alert('Upload รูปเท่านั้น');history.back();</script>";
exit();
}
}
$sql = "insert into webboard_question values('','$topic','$detail',$date,'$ip','0','0','$newname','$username','$id','$newnameM')";
mysql_query($sql)or die("insert Q error");
echo "<script>alert('AddTopic Complete');window.location='indexwebboard.php';</script>";
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
=======================
ขอบคุณมากๆ เลยค่ะ
Tag : - - - -
|
|
|
|
|
|
Date :
3 ม.ค. 2551 17:57:07 |
By :
attas |
View :
1875 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พี่งงกับโค้ดมากเลย
เหมือนเคยเขียน ASP มาแล้วเอารูปแบบการเขียนมาใช้ในภาษา PHP
ส่วนนี้เขียนในหน้า AddTopicForm.php นะคะ
<img src="../member/userPic/<? echo $row['userPic']; ?>" width="<? echo $w; ?>" height="<? echo $h; ?>" border="0"><br>
<input type="hidden" name="userPic" value="../member/userPic/<? echo $row['userPic']; ?>" > ไม่แน่ใจว่า รูป ส่งไปแบบ hidden ได้มั๊ยคะ
<input type="hidden" name="username" value="<? echo $_SESSION['username']; ?>" >
<strong class="site">
<? echo $_SESSION['username']; ?>
<br>
</strong>
<span class="site">
<input type="hidden" name="id" value="<? echo $row['id']; ?>" >
ID : <? echo m00.$row[id]; ?> </span>
++++++++++++++++++++++++++++++
ส่วนนี้เขียนในหน้า AddTopicSave.php นะคะ
<? session_start(); ///// ฟังก์ชั่นนี้ต้องอยู่บันทัดที่ 1 ของไฟล์เท่านั้น
include("../connect.php");
$topic = $_POST['topic'];
$detail = $_POST['detail'];
$date = date("y-m-d");
$ip = $_SERVER['REMOTE_ADDR'];
$attach = $_FILES['attach'];
$newname = "";
$username = $_POST['username'];
$id = $_POST['id'];
$userPic = $_POST['userPic']; ** userPic ที่รับมา อยู่ที่ member/userPic/file.type จะไปเก็บเป็นชื่อใหม่ใน webboard/userPic/newnamefile.type ค่ะ code ผิดมั๊ยคะ
$newnameM = "";
//รูปประกอบกระทู้ให้ attach รูปได้เฉพาะ gif หรือ jpeg
if($attach['size']>0)
{
if($attach['type']=="image/pjpeg")
{ //ถ้ารูปเป็น gif หรือ jpeg ให้ตั้งชื่อรูปตามค่าเวลาที่เพิ่มขึ้นเป็นวินาที และเอาไปเก็บไว้ใน folder attach
$newname = time().".jpg"; move_uploaded_file($attach['tmp_name'],"attach/$newname");
}else if($attach['type']=="image/gif")
{
$newname = time().".gif";
move_uploaded_file($attach['tmp_name'],"attach/$newname");
}else //ถ้ารูปไม่ใช่ gif และ jpeg ให้ฟ้อง error
{
echo "<script>alert('Upload รูปเท่านั้นคร๊าบ');history.back();</script>";
exit();
}
}
//รูปสมาชิก ให้ attach รูปได้เฉพาะ gif หรือ jpeg
$userpic=$_POST['userPic'];
if(filesize($userpic)>0)
{
if(filetype($userpic)=="image/pjpeg")
{ //เก็บไว้ใน folder userPic
$newnameM = "userPic/".date("His").".jpg";
copy($userpic,$newnameM);
}else if (filetype($userpic)=="image/gif")
{
$newnameM = "userPic/".date("His").".gif";
copy($userpic,$newnameM);
}else
{
echo "<script>alert('Upload รูปเท่านั้น');history.back();</script>";
exit();
}
}
$sql = "insert into webboard_question values('','$topic','$detail',$date,'$ip','0','0','$newname','$username','$id','$newnameM')";
mysql_db_query($dbname,$sql) or die("insert Q error");
echo "<script>alert('AddTopic Complete');
window.location='indexwebboard.php';</script>";
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
พี่ว่าส่งไฟล์มาให้พี่แก้ให้น่าจะโอเคกว่า
|
|
|
|
|
Date :
6 ม.ค. 2551 10:07:32 |
By :
bing |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|