|
|
|
รบกวนสอบถามโคด php หน่อยครับผม เกี่ยวกับการ upload และ resize รูปครับ จากโคดที่ถามครับผม ขอบคุนมากครับ |
|
|
|
|
|
|
|
Code (PHP)
<? include("../inc_properties.php");
include("../connect.php");
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body><?
$ddate=date("Y-m-d H:i:s");
$fileupload2 = $_FILES['photo2']['tmp_name'];
$fileupload_name2 = $_FILES['photo2']['name'];
$ext2 = strtolower(end(explode('.', $fileupload_name2)));
$fileupload3 = $_FILES['photo3']['tmp_name'];
$fileupload_name3 = $_FILES['photo3']['name'];
$ext3 = strtolower(end(explode('.', $fileupload_name3)));
$fileupload4 = $_FILES['photo4']['tmp_name'];
$fileupload_name4 = $_FILES['photo4']['name'];
$ext4 = strtolower(end(explode('.', $fileupload_name4)));
$fileupload5 = $_FILES['photo5']['tmp_name'];
$fileupload_name5 = $_FILES['photo5']['name'];
$ext5 = strtolower(end(explode('.', $fileupload_name5)));
$sql="select * from tb_albumactivity where ID_ALB='$id_album'";
$result_check = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
$num=mysql_num_rows($result_check);
if($num==0)
{
$sql="insert into tb_albumactivity (
ID_ALB,
NAME_ALB,
DATE_ALB,
ID_USER
)values(
'0',
'$namealbum',
'$ddate',
'$LOGIN_ID'
)";
$result = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
$sql="select * from tb_albumactivity where DATE_ALB='$ddate'";
$resultt = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
$eng=mysql_fetch_array($resultt);
$id_album=$eng["ID_ALB"];
}else{}
if($photo1!="")
{
$fileupload1 = $_FILES['photo1']['tmp_name'];
$fileupload_name1 = $_FILES['photo1']['name'];
$ext1 = strtolower(end(explode('.', $fileupload_name1)));
if ($ext1 == "jpg" or $ext1 == "jpeg" or $ext1 == "png" or $ext1 == "gif")
{
$ch = copy($photo1,"../photo/$fileupload_name1");
$filepicupload1 = "photo/$fileupload_name1";
$sql="insert into tb_pictureactivity (
ID,
ID_ALB,
NAME_PIC,
DATE_PICTURE
)values(
'0',
'$id_album',
'$filepicupload1',
'$ddate'
)";
$result_pic1 = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
}
else
{
echo "<script language = 'javascript'>alert('ขอโทษค่ะ! ไม่สามารถอัพโหลดรูปได้ค่ะ');</script>";
}
}
else{}
if($photo2!="")
{
if ($ext2 == "jpg" or $ext2 == "jpeg" or $ext2 == "png" or $ext2 == "gif")
{
$ch = copy($photo2,"../photo/$fileupload_name2");
$filepicupload2 = "photo/$fileupload_name2";
$sql="insert into tb_pictureactivity (
ID,
ID_ALB,
NAME_PIC,
DATE_PICTURE
)values(
'0',
'$id_album',
'$filepicupload2',
'$ddate'
)";
$result_pic2 = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
}
else
{
echo "<script language = 'javascript'>alert('ขอโทษค่ะ! ไม่สามารถอัพโหลดรูปได้ค่ะ');</script>";
}
}
else{}
if($photo3!="")
{
if ($ext3 == "jpg" or $ext3 == "jpeg" or $ext3 == "png" or $ext3 == "gif")
{
$ch = copy($photo3,"../photo/$fileupload_name3");
$filepicupload3 = "photo/$fileupload_name3";
$sql="insert into tb_pictureactivity (
ID,
ID_ALB,
NAME_PIC,
DATE_PICTURE
)values(
'0',
'$id_album',
'$filepicupload3',
'$ddate'
)";
$result_pic3 = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
}
else
{
echo "<script language = 'javascript'>alert('ขอโทษค่ะ! ไม่สามารถอัพโหลดรูปได้ค่ะ');</script>";
}
}
else{}
if($photo4!="")
{
if ($ext4 == "jpg" or $ext4 == "jpeg" or $ext4 == "png" or $ext4 == "gif")
{
$ch = copy($photo4,"../photo/$fileupload_name4");
$filepicupload4 = "photo/$fileupload_name4";
$sql="insert into tb_pictureactivity (
ID,
ID_ALB,
NAME_PIC,
DATE_PICTURE
)values(
'0',
'$id_album',
'$filepicupload4',
'$ddate'
)";
$result_pic4 = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
}
else
{
echo "<script language = 'javascript'>alert('ขอโทษค่ะ! ไม่สามารถอัพโหลดรูปได้ค่ะ');</script>";
}
}
else{}
if($photo5!="")
{
if ($ext5 == "jpg" or $ext5 == "jpeg" or $ext5 == "png" or $ext5 == "gif")
{
$ch = copy($photo5,"../photo/$fileupload_name5");
$filepicupload5 = "photo/$fileupload_name5";
$sql="insert into tb_pictureactivity (
ID,
ID_ALB,
NAME_PIC,
DATE_PICTURE
)values(
'0',
'$id_album',
'$filepicupload5',
'$ddate'
)";
$result_pic5 = mysql_query($sql) or die(error_msg(mysql_error(),$sql));
}
else
{
echo "<script language = 'javascript'>alert('ขอโทษค่ะ! ไม่สามารถอัพโหลดรูปได้ค่ะ');</script>";
}
}
else{}
mysql_close();
?>
<style type="text/css">
<!--
.style1 {color: #006600}
-->
</style>
<br><br><br>
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
document.location.href = '../addalbum/indexconfirmalbum.php?id_album=<?=$id_album?>';
// End -->
</script>
</body>
</html>
ผมขอสอบถามหน่อยครับ
จากโคดข้างบนนี้ สามารถทำให้เวลา อัพโหลดรูปสำเร็จแล้ว ให้โคดเปลี่ยนชื่อไฟลรูปเอง และ ฟิกขนาดรูป หรือ resize รูป ทำไรอย่างไรหลอครับ รบกวนดูโคด และช่วยบอกทีนะครับ
ขอบคุณมากครับ
Tag : PHP
|
|
|
|
|
|
Date :
2012-01-15 15:07:34 |
By :
Featherd |
View :
935 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|