Wed 2 Aug 2006 10:34:01
คือผมอยากเพิ่มสคริป insert ภาพเข้าไปเก็บในดาต้าเบส แต่ผมไม่รู้ว่าจะนำโค้ดที่ได้จากเว็บอื่นมาดัดแปลงใส่ยังไงเพื่อให้ภาพที่เรา insert มาเนี่ย ให้มัน save ลงไปที่ ดาต้าเบส หรือเอาเชื่อลง ดาต้าเบส แล้วทำลิงค์ดึงภาพมาโชว์จากไฟล์ชื่อ view.php เพื่อดึงภาพมาโชว์นะครับ แล้วต้องใส่ path ยังไงอ่ะครับยังไงแนะนำด้วยครับ
สคริปที่ได้จากเว็บอื่น
// Insert picture
// Uploading / Edit thumbnail pictures
$ufile = 'thumb';
if ($_FILES[$ufile]['name'] != ""){
$filename = stripslashes($_FILES[$ufile]['name']);
$filesize = $_FILES[$ufile]['size'];
$pic_d = getimagesize($_FILES[$ufile]['tmp_name']);
switch($pic_d[2]){
case 1 : $ft = "gif"; break;
case 2 : $ft = "jpg"; break;
case 3 : $ft = "png"; break;
}
$spath = "../_event/pic/";
$uploadfile = $spath.$filename;
if (!(is_dir($spath))){ mkdir($spath); }
if(!empty($_FILES[$ufile]) && $pic_d) {
if (move_uploaded_file($_FILES[$ufile]['tmp_name'] ,$uploadfile)){
$cimage = $uploadfile;
$imgg = ", `image` = '$cimage' ";
}
}
}
ไฟล์ index.php
<?
$DEFINE_SITE = true;
include "../../../includes/common.php";
include "../../../includes/template.php";
$template = new template();
$v = initial($ck);
//if ($mem[rank] > 0){
$step = ($_POST[vote] != "" ? 1 : 0);
if ($_POST[poll1] != "" && $step > 0){
$startpage = "finish.html";
$poll = $_POST[poll1];
query("INSERT INTO `post_picture` SET `mem_no` = '$mem[no]' , `mem_name` = '$mem[name]' , `poll` = '$poll' , `topic` = '$topic' , `comment` = '$comment' , `image` = '$image' , `time` = '$time'");
if (mysql_insert_id() > 0){
$template->assign_block_vars('fin',null);
} else {
$template->assign_block_vars('al',null);
}
} else {
$startpage = "main.html";
}
//} else {
//$startpage = "member.html";
//}
$template->set_filenames(array(
'body' => $startpage,
));
$page_title = "Online-Station Activity :: Dark Story";
$template->pparse('body');
?>
ไฟล์ชื่อ main.html
| หัวข้อบรรยาย | |
| คำบรรยาย | |
| ใส่ภาพประกอบ | |
Wed 2 Aug 2006 11:14:00
ผมลองเอาโค้ดใส่เข้าไปแล้วครับแบบข้างล่าง ช่อง Brows ภาพมาชื่อ img พอกดปุ่มเพื่อส่งข้อมูล ข้อมูลส่วน หัวข้อบรรยาย,คำบรรยาย , วันที่มัน add เข้าดาต้าเบสหมด แต่ภาพไม่ไปครับ เป็นเพราะอะไรเอ่ย
<?
$DEFINE_SITE = true;
include "../../../includes/common.php";
include "../../../includes/template.php";
$template = new template();
$v = initial($ck);
//if ($mem[rank] > 0){
$step = ($_POST[vote] != "" ? 1 : 0);
if ($_POST[poll1] != "" && $step > 0){
$startpage = "finish.html";
$poll = $_POST[poll1];
//--------------
// Insert picture
// Uploading / Edit thumbnail pictures
$ufile = 'img';
if ($_FILES[$ufile]['name'] != ""){
$filename = stripslashes($_FILES[$ufile]['name']);
$filesize = $_FILES[$ufile]['size'];
$pic_d = getimagesize($_FILES[$ufile]['tmp_name']);
switch($pic_d[2]){
case 1 : $ft = "gif"; break;
case 2 : $ft = "jpg"; break;
case 3 : $ft = "png"; break;
}
$spath = "/pic_mam/";
$uploadfile = $spath.$filename;
if (!(is_dir($spath))){ mkdir($spath); }
if(!empty($_FILES[$ufile]) && $pic_d) {
if (move_uploaded_file($_FILES[$ufile]['tmp_name'] ,$uploadfile)){
$cimage = $uploadfile;
$imgg = ", `image` = '$cimage' ";
}
}
}
// End upload section
//------------
query("INSERT INTO `post_picture` SET `mem_no` = '$mem[no]' , `mem_name` = '$mem[name]' , `poll` = '$poll' , `topic` = '$topic' , `comment` = '$comment' , `time` = '$time' $imgg");
if (mysql_insert_id() > 0){
$template->assign_block_vars('fin',null);
} else {
$template->assign_block_vars('al',null);
}
} else {
$startpage = "main.html";
}
//} else {
//$startpage = "member.html";
//}
$template->set_filenames(array(
'body' => $startpage,
));
$template->pparse('body');
?>

















