|
|
|
รบกวนช่วยแก้โค๊ดอัพโหลดรูปหลายๆรูปหน่อยครับ รบกวนหน่อยนะครับ งงมากมาย |
|
|
|
|
|
|
|
activity_photo.php
<?php
include("chksession.php");
include("config.inc.php");
$id_name=$_GET['id_name'];
$sql="select * from tbl_name_photo where id_name='$id_name'";
$result=mysql_db_query($dbname,$sql);
$rs=mysql_fetch_array($result);
$name_photo=$rs[name_photo];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title><?php echo"$titlename";?></title>
<style type="text/css">
<!--
body {
margin-top: 0px;
margin-bottom: 0px;
}
-->
</style>
<script language="javascript">
function fncCreateElement(){
var mySpan = document.getElementById('mySpan');
var myElement1 = document.createElement('input');
myElement1.setAttribute('type',"file");
myElement1.setAttribute('name',"photo[]");
//myElement1.setAttribute('id',"filUpload[]");
mySpan.appendChild(myElement1);
//*** Remove Element ***//
/*
var deleteEle = document.getElementById('txt1');
mySpan.removeChild(deleteEle);
*/
var myElement2 = document.createElement('<br>');
mySpan.appendChild(myElement2);
}
</script>
</head>
<body>
<form action="activity_photo_add.php" method="post" name="form1" id="form1" enctype="multipart/form-data">
:: ระบบเพิ่มรูป Gallery งานกิจกรรม ::<br/>
ชื่อกิจกรรม :<?=$name_photo?><br/>
รูปภาพ :
<input type="file" name="photo" size="50" />
<input name="btnButton" id="btnButton" type="button" value="+" onClick="JavaScript:fncCreateElement();">
<br>
<span id="mySpan"></span>
<br/>คำอธิบายรูปภาพ :<br/>
<textarea name="txt_detail" id="txt_detail" cols="60" rows="5"></textarea><br/>
<input name="button" type="submit" class="FontNew1" id="button" value="เพิ่มรูปภาพลง Gallery" />
<input name="button2" type="reset" class="FontNew1" id="button2" value="ล้างจอภาพ" /><br/>
<input type="hidden" name="id_name" value="<?=$id_name?>" />
</form>
<?php
$no=0;
$sql="select * from tbl_detail_photo where ref_title='$id_name' order by id_photo";
$result=mysql_db_query($dbname,$sql);
$num=mysql_num_rows($result);
if($num>0) {
echo "<div align='center'>
<TABLE BORDER=1 width='800px'>
<TR BGCOLOR=#EEEEEE>
<TD>ลำดับ</B></TD>
<TD><B>รูปภาพ</B></TD>
<TD><B>รายละเอียด</B></TD>
<TD><B>ลบ</B></TD>
</TR> </div>";
while ($r=mysql_fetch_array($result)) {
$id_photo=$r[id_photo];
$name_photo=$r[name_photo];
$detail_photo=$r[detail_photo];
$no++;
echo "
<TR>
<TD><CENTER>$no</CENTER></TD>
<TD>
<A HREF='images_large/$name_photo' TARGET='_blank'>
<IMG SRC='images_small/$name_photo' BORDER=0></A></TD>
<TD>$detail_photo</TD>
<TD><A HREF='activity_del.php?id_del=$id_photo&id_name=$id_name&name_del=$name_photo'
onclick=\"return confirm('คุณแน่ใจที่จะลบรูป $name_photo ออกจการะบบ')\">ลบ</A>
</TD> </TR>";
}
}
?>
</body>
</html>
คือผมไม่รู้ว่าจะใส่ For เริ่มต้นจากตรงไหนดีอะครับ
activity_photo_add
<?php
$photo=$_FILES['photo']['tmp_name'];
$photo_name=$_FILES['photo']['name'];
$photo_size=$_FILES['photo']['size'];
$photo_type=$_FILES['photo']['type'];
$detail=$_POST['txt_detail'];
$id_name=$_POST['id_name'];
if(!$photo) {
echo"<script>alert('ไม่สามารถ Upload รูปภาพได้ค่ะ')</script>";
echo"<script>window.location='activity_photo.php?id_name=$id_name'</script>";
exit();
}
$ext=strtolower(end(explode('.',$photo_name)));
if($ext=="jpg" or $ext=="jpeg" or $ext=="png" or $ext=="gif"){
//เพิ่มข้อมูลลงตาราง tbl_detail_photo
include("config.inc.php");
$sql="insert into tbl_detail_photo values(null,'','$detail','$id_name')";
mysql_db_query($dbname,$sql);
// หา id_photo ที่มากที่สุด ของ tbl_detail_photo
$sql="select max(id_photo) from tbl_detail_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_h =100;
$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_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);
*/
$ori_size = getimagesize($photo);
$ori_w = $ori_size[0];
$ori_h = $ori_size[1];
if ($ori_w>=$ori_h) {
$new_w = 3000;
$new_h = round(($new_w/$ori_w) * $ori_h);
} else {
$new_h =3000;
$new_w = round(($new_h/$ori_h) * $ori_w);
}
$photo= imagecreatetruecolor($new_w, $new_h);
imagecopyresized($photo, $ori_img,0,0,0,0,$new_w, $new_h,$ori_w,$ori_h);
if ($ext =="jpg" or $ext =="jpeg") {
imagejpeg($photo,"images_large/$filename");
} else if ($ext =="png") {
imagepng($photo,"images_large/$filename");
} else if ($ext =="gif") {
imagegif($photo,"images_large/$filename");
}
/*เซตขนาดรูปภาพ*/
$new_w = 500;
$new_h =400;
$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);
imagedestroy($photo);
$sql="update tbl_detail_photo set name_photo='$filename' where id_photo='$id_max' ";
mysql_db_query($dbname,$sql);
echo"<script>alert('Upload รูปภาพเรียบร้อยแล้วค่ะ')</script>";
echo"<script>window.location='activity_photo.php?id_name=$id_name'</script>";
mysql_close();
} else {
echo"<script>alert('ขออภัยค่ะ ไม่สามารถ upload รูปภาพได้ค่ะ')</script>";
echo"<script>window.location='activity_photo.php?id_name=$id_name'</script>";
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
Tag : PHP
|
ประวัติการแก้ไข 2013-07-16 02:11:55
|
|
|
|
|
Date :
2013-07-14 19:41:23 |
By :
lchampl123 |
View :
710 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ติดตรงไหนครับ
PHP MySQL Multiple Upload File to MySQL Database - CreateElement Input File Upload
|
|
|
|
|
Date :
2013-07-15 06:30:59 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|