|
 |
|
ช่วยดูโค้ดให้ทีครับ insert ข้อมูล กับ รูป ลง database ข้อมูลลงแต่รูปไม่ลงครับ งง มาก |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
if($_POST[action]=="save"){
$fileload=$_FILES['fileload']['tmp_name'];
$fileload_name=$_FILES['fileload']['name'];
$fileload_size=$_FILES['fileload']['size'];
$fileload_type=$_FILES['fileload']['type'];
//check data//
if($_POST[name_sub]=="" or $_POST[code]=="" or $_POST[type]=="กรุณาเลือก" or $_POST[cc]=="" or $_POST[year]=="" or $_POST[fileload]==""){
echo "<script>alert('กรุณาใส่ข้อมูลให้ครบ');history.back();</script>";
exit();
}
if($fileload_size>"100000"){
echo "<script>alert('รูปภาพมีขนาดเกิน200kb');history.back();</script>";
exit();
}
//end check//
//insert data//
$data = array(
"name_sub"=>addslashes($_POST[name_sub]),
"code"=>addslashes($_POST[code]),
"id_product"=>addslashes($_POST[type]),
"cc"=>$_POST[cc],
"year"=>$_POST[year],
"date_post"=>date("Y-m-d"),
);
insert("tb_stlsub_product",$data);
//end insert//
//upload picture//
if ($fileload) {
$array_last=explode(".",$fileload_name);
$c=count($array_last)-1;
$lastname=strtolower($array_last[$c]) ;
if ($lastname=="gif" or $lastname=="jpg" or $lastname=="jpeg") {
$sql="select max(id) from tb_stlsub_product";
$row = mysql_fetch_row(mysql_query($sql));
$photoname=date("Y-m-d-H-i-s")."_".$row[0].".".$lastname;
}
$ext = strtolower(end(explode('.', $fileload_name)));
if ($ext == "jpg" or $ext == "jpeg" or $ext =="png" or $ext=="gif") {
if ($ext =="jpg" or $ext =="jpeg") {
$ori_img = imagecreatefromjpeg($fileload);
} else if ($ext =="png") {
$ori_img = imagecreatefrompng($fileload);
} else if ($ext =="gif") {
$ori_img = imagecreatefromgif($fileload);
}
$ori_size = getimagesize($fileload);
$ori_w = $ori_size[0];
$ori_h = $ori_size[1];
if ($ori_w>=$ori_h and $ori_w >321) {
$new_w = 321;
$new_h = round(($new_w/$ori_w) * $ori_h);
$new_img= imagecreatetruecolor($new_w, $new_h);
imagecopyresized( $new_img, $ori_img,0,0,0,0,$new_w, $new_h,$ori_w,$ori_h);
if ($ext =="jpg" or $ext =="jpeg") {
imagejpeg($new_img,"images/imagestl/sub_product/".$photoname);
} else if ($ext =="png") {
imagepng($new_img,"images/imagestl/sub_product/".$photoname);
} else if ($ext =="gif") {
imagegif($new_img,"images/imagestl/sub_product/".$photoname);
}
imagedestroy($ori_img);
imagedestroy($new_img);
} else if ($ori_h>=$ori_h and $ori_h >246) {
$new_h = 246;
$new_w = round(($new_h/$ori_h) * $ori_w);
$new_img= imagecreatetruecolor($new_w, $new_h);
imagecopyresized($new_img, $ori_img,0,0,0,0,$new_w, $new_h,$ori_w,$ori_h);
if ($ext =="jpg" or $ext =="jpeg") {
imagejpeg($new_img,"images/imagestl/sub_product/".$photoname);
} else if ($ext =="png") {
imagepng($new_img,"images/imagestl/sub_product/".$photoname);
} else if ($ext =="gif") {
imagegif($new_img,"images/imagestl/sub_product/".$photoname);
}
imagedestroy($ori_img);
imagedestroy($new_img);
}else{
copy($fileload,"images/imagestl/sub_product/".$photoname);
}
}//end if($ext==jpg)//
}//end if($fileupload)//
$data = array(
"pic"=>addslashes($photoname),
);
update("tb_stlsub_product",$data,"id='$row[0]'");
unlink($fileload);
//end upload//
unset($_POST[action]);
?>
<SCRIPT LANGUAGE="JavaScript">alert("add content suscessfully");window.location='stl_addsub.php?mode=stl_addsub.php';</script>
<?
}//end $_POST[action]//
?>
ข้อมูลตรง insert ลงหมดแต่รูปไม่ลง แต่มันก็ขึ้น alert ข้อความ success นะ งงครับ ช่วยดูที
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2012-07-04 16:44:05 2012-07-04 16:46:00
|
 |
 |
 |
 |
Date :
2012-07-04 16:41:06 |
By :
golden014 |
View :
977 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูที่ form ครับว่ากำหนด enctype="multipart/form-data" ไว้หรือเปล่า
|
 |
 |
 |
 |
Date :
2012-07-04 17:46:48 |
By :
Dragons_first |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้การ debug ด้วยการ echo "test"; ไปเรื่อย ๆ ครับ ดูว่ามันไม่ทำงานตรงไหน
|
 |
 |
 |
 |
Date :
2012-07-04 21:45:06 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|