|
 |
|
รบกวนด้วยค่ะ อาทิตย์หนึ่งแ้ล้ว ยังแก้ไม่ได้เลย ขอบคุณมากๆ เลยค่ะ |
|
 |
|
|
 |
 |
|
<?
$photo=$_FILES['photo']['tmp_name'];
$photo_name=$_FILES['photo']['name'];
$photo_size=$_FILES['photo']['size'];
$photo_type=$_FILES['photo']['type'];
$detail=$_POST['detail'];
$id_title=$_POST['id_title'];
if (!$photo){
echo "<h3>error:ไม่สามารถ upload รูปภาพได้</h3>";
exit();
}
$ext=strtolower(end(explode('.',$photo_name)));
if($ext == "jpg" or $ext == "jpeg" or $ext == "png" or $ext == "gif") {
include "connect.php";
$sql="insert into tb_photo values (null,' ','$detail','$id_title') ";
mysql_db_query($dbname,$sql);
$sql="select max(id_photo) from tb_photo";
$result=mysql_db_query($dbname,$sql);
$r=mysql_fetch_array($result);
$id_max=$r[0];
$filename=$id_max.".".$ext;
copy($photo,"images_large/$filename");
if($ext=="jpg" or $ext=="jpeg") {
$ori_img=imagecreatefromjpeg($photo);
} else if ($ext=="png") {
$ori_img=imagecreatefrompng($photo);
}else if ($ext=="gif"){
$ori_img=imagecreatefromgif($photo);
}
$ori_size=getimagesize($photo);
$ori_w=$ori_size[0];
$ori_h=$ori_size[1];
if($ori_w>=$ori_h) {
$new_w=100;
$new_h=round(($new_w/$ori_w)*$ori_h);
} else {
$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_small/$filename");
} else if($ext == "png") {
imagepng($new_img,"images_small/$filename");
} else if($ext == "gif") {
imagegif($new_img,"images_small/$filename");
}
imagedestroy($ori_img);
imagedestroy($new_img);
$sql="update tb_photo set name_photo='$filename' where id_photo='$id_max' ";
mysql_db_query($dbname,$sql);
echo"<h3>upload รูปภาพเรียบร้อยแล้ว</h3>";
echo"<a href='admin_photo.php?id_title=$id_title'>กลับหน้าหลัก</a>";
mysql_close();
echo "<h3>error: ไม่สามารถ upload รูปภาพได้ครับ</h3>";
}
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2011-01-28 19:10:29 |
By :
noksawa |
View :
798 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันขึ้นว่าแบบนี้น่ะค่ะ
Parse error: syntax error, unexpected T_ELSE in C:\AppServ\www\photo2\admin_photo_add.php on line 53
|
 |
 |
 |
 |
Date :
2011-01-28 19:14:37 |
By :
noksawa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขาด } ตัวสุดท้ายอีกตัวนึงครับ
|
 |
 |
 |
 |
Date :
2011-01-29 04:09:59 |
By :
PlaKriM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆ เลยนะค่ะ แต่มันก็ยังไม่ได้อยู่ดีค่ะ T_T
|
 |
 |
 |
 |
Date :
2011-01-29 13:48:34 |
By :
noksawa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูแล้วไม่มี syntax error หลังจากเพิ่ม } ตามที่บอกนะครับ แต่อาจจะมีปัญหาจากส่วนอื่นแทน
Code (PHP)
<?php
$photo = $_FILES['photo']['tmp_name'];
$photo_name = $_FILES['photo']['name'];
$photo_size = $_FILES['photo']['size'];
$photo_type = $_FILES['photo']['type'];
$detail = $_POST['detail'];
$id_title = $_POST['id_title'];
if (!$photo){
echo "<h3>error:ไม่สามารถ upload รูปภาพได้</h3>";
exit();
}
$ext=strtolower(end(explode('.',$photo_name)));
if($ext == "jpg" or $ext == "jpeg" or $ext == "png" or $ext == "gif") {
include "connect.php";
$sql = "insert into tb_photo values (null,' ','$detail','$id_title') ";
mysql_db_query($dbname,$sql);
$sql = "select max(id_photo) from tb_photo";
$result = mysql_db_query($dbname,$sql);
$r = mysql_fetch_array($result);
$id_max = $r[0];
$filename = $id_max.".".$ext;
copy($photo,"images_large/$filename");
if($ext=="jpg" or $ext=="jpeg") {
$ori_img=imagecreatefromjpeg($photo);
} else if ($ext=="png") {
$ori_img=imagecreatefrompng($photo);
}else if ($ext=="gif"){
$ori_img=imagecreatefromgif($photo);
}
$ori_size=getimagesize($photo);
$ori_w=$ori_size[0];
$ori_h=$ori_size[1];
if($ori_w>=$ori_h) {
$new_w=100;
$new_h=round(($new_w/$ori_w)*$ori_h);
} else {
$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_small/$filename");
} else if($ext == "png") {
imagepng($new_img,"images_small/$filename");
} else if($ext == "gif") {
imagegif($new_img,"images_small/$filename");
}
imagedestroy($ori_img);
imagedestroy($new_img);
$sql="update tb_photo set name_photo='$filename' where id_photo='$id_max' ";
mysql_db_query($dbname,$sql);
echo"<h3>upload รูปภาพเรียบร้อยแล้ว</h3>";
echo"<a href='admin_photo.php?id_title=$id_title'>กลับหน้าหลัก</a>";
mysql_close();
echo "<h3>error: ไม่สามารถ upload รูปภาพได้ครับ</h3>";
}
}
?>
|
 |
 |
 |
 |
Date :
2011-01-30 15:51:58 |
By :
zankumuro |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|