Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > Insert และ Update รูป... Rename,Resize แบบมี Thumb เห็นถามกันบ่อยเลยเอามาลงให้ครับ...



 

Insert และ Update รูป... Rename,Resize แบบมี Thumb เห็นถามกันบ่อยเลยเอามาลงให้ครับ...

 



Topic : 048439



โพสกระทู้ ( 615 )
บทความ ( 4 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์




Upload...
<?
	error_reporting(E_ALL ^ E_NOTICE);
        session_start();
	//require("../auth.inc.php");
	$photo = $_FILES['photo']['tmp_name'];
	$photo_name = $_FILES['photo']['name'];
	$photo_size = $_FILES['photo']['size'];
	
	//$user = $_SESSION['ses_user'];

	date_default_timezone_set('Asia/Bangkok');
	$time = date("Y-m-d-H-i-s");
	$ext = strtolower(end(explode('.', $photo_name)));

if($ext!="jpg" and $ext!="jpeg" and $ext!="png" and $ext!="gif"){
		?>
            <html>
            <title>Upload Failed...</title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <meta http-equiv="refresh" content="2.8; url=my_account.php" >
            <style type="text/css">
                html { height:100%; width:100%; }
                body { 
                    width:100%; 
                    height:100%; 
                    margin:0px; 
                    padding:0px; 
                    border:0px;
                    font-family: Verdana, Geneva,Segoe UI, sans-serif;
                    font-size:13px; 
                    line-height:15px;
                }
                .bg{
                    height:92%;
                    width:100%;
                    margin-bottom:0px;
                    background:url(../images/sky_bg.jpg);
                }
                .footerl{
                    width:100%;
                    height:8%;
                    margin-bottom:0px;
                    border:0px;
                    background-color:#09F;
                }
            </style>
            <div class="bg">
            <?
            	echo "<br /> &nbsp; ไม่สามารถอัปโหลด ".$photo_name." ,&nbsp; ( .".$ext." )";
			?>
            <center>
            <br /><br />
            <img src="../images/Security_graphic.png" border="0" /><br /><br /><br />
            <b><font color="#000099" size="+1" face="Comic Sans MS, cursive">Can not upload ! รอสักครู่ ...</font></b></center>
            <br /><br /><br />
            </div>
            <div class="footerl">
                <center>
                    <table height="100%" width="100%" border="0" cellpadding="0" cellspacing="2">    	
                        <tr>
                            <td bgcolor="#00FFFF">
                                <center><font size="-1">
                                    CopyRight @
                                    </font>
                                </center>
                            </td>
                        </tr>
                    </table>
                </center>
            </div>
        </html>
      <?
		exit();
}else{		
	$file_name = $time."-".session_id().".".$ext;
	if($ext == "jpg" or $ext == "jpeg" or $ext == "png" or $ext == "gif"){
		//copy($photo,$file_name);
		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 > 84){
			$new_w = 84;
			$new_h = round(($new_w/$ori_w) * $ori_h);
			$new_img = imagecreatetruecolor($new_w, $new_h);
			$thumb = imagecreatetruecolor(30, 30);
			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/avatar_user/$file_name");
				imagecopyresized($thumb, $ori_img, 0,0,0,0, 30, 30, $ori_w, $ori_h);
				imagejpeg($thumb,"../images/avatar_thumb/$file_name");
			}else if($ext == "png"){
				imagepng($new_img,"../images/avatar_user/$file_name");
				imagecopyresized($thumb, $ori_img, 0,0,0,0, 30, 30, $ori_w, $ori_h);
				imagepng($thumb,"../images/avatar_thumb/$file_name");
			}else if($ext == "gif"){
				imagegif($new_img,"../images/avatar_user/$file_name");
				imagecopyresized($thumb, $ori_img, 0,0,0,0, 30, 30, $ori_w, $ori_h);
				imagegif($thumb,"../images/avatar_thumb/$file_name");
			}
			imagedestroy($new_img);
			imagedestroy($thumb);
		}else{
			$ori_size = getimagesize($photo);
			$ori_w = $ori_size[0];
			$ori_h = $ori_size[1];
			$new_img = imagecreatetruecolor(30, 30);
			if($ext == "jpg" or $ext == "jpeg"){
				imagejpeg($ori_img,"../images/avatar_user/$file_name");
				imagecopyresized($new_img, $ori_img, 0,0,0,0, 30, 30, $ori_w, $ori_h);
				imagejpeg($new_img,"../images/avatar_thumb/$file_name");
			}else if($ext == "png"){
				imagepng($ori_img,"../images/avatar_user/$file_name");
				imagecopyresized($new_img, $ori_img, 0,0,0,0, 30, 30, $ori_w, $ori_h);
				imagepng($new_img,"../images/avatar_thumb/$file_name");
			}else if($ext == "gif"){
				imagegif($ori_img,"../images/avatar_user/$file_name");
				imagecopyresized($new_img, $ori_img, 0,0,0,0, 30, 30, $ori_w, $ori_h);
				imagegif($new_img,"../images/avatar_thumb/$file_name");			
			}
		}
		
		require("../includes/connection.php");
		mysql_select_db($db_name,$conn);
		mysql_query("SET NAMES UTF8",$conn);
		
		$sql_select = "SELECT photo FROM user WHERE user_name='$_SESSION[ses_user]' ";
		$db_query_photo = mysql_query($sql_select,$conn) or die("Error Qeury [".$db_query."]");
		$sql_photo = mysql_fetch_array($db_query_photo);
		$selected = $sql_photo['photo'];
		
		if($selected != NULL){
			$sql_update ="UPDATE user SET photo='$file_name',last_update='$time' WHERE user_name='$_SESSION[ses_user]' ";
			mysql_db_query($db_name,$sql_update);
			unlink("../images/avatar_user/$selected");
			unlink("../images/avatar_thumb/$selected");
		}else{
			$sql_insert = "INSERT INTO user (photo,last_update) VALUES('$file_name','$time') WHERE user_name='$_SESSION[ses_user]' ";
			mysql_db_query($db_name,$sql_insert);
		}
		imagedestroy($ori_img);
	}else{
	?>
    <html>
        <title>Upload Failed...</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="refresh" content="2.8; url=my_account.php" >
        <style type="text/css">
            html { height:100%; width:100%; }
            body { 
                width:100%; 
                height:100%; 
                margin:0px; 
                padding:0px; 
                border:0px;
                font-family: Verdana, Geneva,Segoe UI, sans-serif;
                font-size:13px; 
                line-height:15px;
            }
            .bg{
                height:92%;
                width:100%;
                margin-bottom:0px;
                background:url(../images/sky_bg.jpg);
            }
            .footerl{
                width:100%;
                height:8%;
                margin-bottom:0px;
                border:0px;
                background-color:#09F;
            }
        </style>
        <div class="bg"><center>
        <br /><br />
        <img src="../images/Security_graphic.png" border="0" /><br /><br /><br />
        <b><font color="#000099" size="+1" face="Comic Sans MS, cursive">Can not upload ! รอสักครู่ ...</font></b></center>
        <br /><br /><br />
        </div>
        <div class="footerl">
            <center>
                <table height="100%" width="100%" border="0" cellpadding="0" cellspacing="2">    	
                    <tr>
                        <td bgcolor="#00FFFF">
                            <center><font size="-1">
                                CopyRight @
                                </font>
                            </center>
                        </td>
                    </tr>
                </table>
            </center>
        </div>
    </html>
    <?
	exit();
	}
	?>
     <html>
        <title>Uploading...</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="refresh" content="3; url=my_account.php" >
        <style type="text/css">
            html { height:100%; width:100%; }
            body { 
                width:100%; 
                height:100%; 
                margin:0px; 
                padding:0px; 
                border:0px;
                font-family: Verdana, Geneva,Segoe UI, sans-serif;
                font-size:13px; 
                line-height:15px;
            }
            .bg{
                height:92%;
                width:100%;
                margin-bottom:0px;
                background:url(../images/sky_bg.jpg);
            }
            .footerl{
                width:100%;
                height:8%;
                margin-bottom:0px;
                border:0px;
                background-color:#09F;
            }
			.fonts{
				font-size:13px;
			}
        </style>
        <div class="bg">
        <?
		echo "&nbsp;&nbsp;<table width=\"500\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\">
  <tr>
    <td width=\"20\" align=\"right\" valign=\"middle\" ><img src=\"../images/animation/loading_small.gif\" border=\"0\" /></td>
    <td width=\"480\" align=\"left\" valign=\"middle\"><div class=\"fonts\">กำลังอัฟโหลด : <b>".$photo_name."</b> ,&nbsp; ขนาด : <b>".$photo_size."</b> Byte</div></td>
  </tr>
</table>";
		?>
        <center>
        <br /><br />
        <img src="../images/pictures-reflect.png" border="0" /><br /><br /><br />
        <b><font color="#000099" size="+1" face="Comic Sans MS, cursive">Uploading : รอสักครู่ ...</font></b></center>
        <br /><br /><br />
        </div>
        <div class="footerl">
            <center>
                <table height="100%" width="100%" border="0" cellpadding="0" cellspacing="2">    	
                    <tr>
                        <td bgcolor="#00FFFF">
                            <center><font size="-1">
                                CopyRight @ 
                                </font>
                            </center>
                        </td>
                    </tr>
                </table>
            </center>
        </div>
    </html>
    <?
		mysql_close();
}
?>

Insert และ Update รูป... Resize แบบมี thumb
เป็นตัวเก่าที่ผมเคยทำไว้...



Tag : PHP









ประวัติการแก้ไข
2010-09-09 01:17:52
2010-09-09 19:38:06
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-09-08 20:27:13 By : t-monroe View : 6340 Reply : 9
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

อ่านเพิ่มเติมได้จากที่นี่ครับ

Go to : PHP Image (GD) : การใช้งาน GD ซึ่งเป็น Module ในการจัดการรูปภาพในภาษา PHP






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-08 20:47:29 By : webmaster
 


 

No. 2

Guest


ขอตัวอย่างแบบสั้นๆ มีไหมค๊ะ ยาวแบบนี้ไม่รู้จะไปปรับแก้ตรงไหนเลย

ขอบคุณนะค๊ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-09 08:06:36 By : มิ้น
 

 

No. 3



โพสกระทู้ ( 1,242 )
บทความ ( 13 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

แบบสั้นๆ โดยใช้ library ของ phpthumnailer
Resize images phpthumnailer
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-09 11:26:58 By : DS_Ohm
 


 

No. 4

Guest


Thanks...
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-09 14:09:12 By : Goddd...
 


 

No. 5



โพสกระทู้ ( 615 )
บทความ ( 4 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


ความจริงถ้าตัด ส่วนที่เป็น HTML ออก มันก็ไม่ยเยอะนะครับ...
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-09 19:37:30 By : t-monroe
 


 

No. 6



โพสกระทู้ ( 52 )
บทความ ( 0 )



สถานะออฟไลน์


แบบว่าเราอัพข้อมูลกับรูปไปแล้ว แต่เราต้องการแก้ไข แต่ตอนแต่ไขนั้นอัพรูปไม่ได้ ต้องทำอย่างไร ??
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-01-25 13:24:28 By : fasaiaya
 


 

No. 7



โพสกระทู้ ( 70 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

อันนี้ code ผมดัดแปลงนิดหน่อยจากใน บทเรียนนะครับ

Multible Upload & Resize ( เพิ่มข้อมูลลง Database M.Access )

HTML CODE
<html>
<head>
<title>Multible Upload & Resize</title>
</head>
<script language="javascript">
	function fncCreateElement(){
		
	   var mySpan = document.getElementById('mySpan');

	   var myLine = document.getElementById('hdnLine');
	   myLine.value++;
	   
	   // Create input file
	   var myElement2 = document.createElement('input');
	   myElement2.setAttribute('type',"file");
	   myElement2.setAttribute('name',"fileUpload"+myLine.value);
	   myElement2.setAttribute('id',"fil"+myLine.value);
	   mySpan.appendChild(myElement2);	
		
       // Create <br>
	   var myElement3 = document.createElement('<br>');
	   myElement3.setAttribute('id',"br"+myLine.value);
	   mySpan.appendChild(myElement3);
	}

	function fncDeleteElement(){

		var mySpan = document.getElementById('mySpan');

		var myLine = document.getElementById('hdnLine');
		
		if(myLine.value > 1 )
		{

			// Remove input file
			var deleteFile = document.getElementById("fil"+myLine.value);
			mySpan.removeChild(deleteFile);

			// Remove <br>
			var deleteBr = document.getElementById("br"+myLine.value);
			mySpan.removeChild(deleteBr);

			myLine.value--;
		}
	}
</script>
<body>
	<form action="multi_upload1.php" method="post" name="form1" enctype="multipart/form-data">
		<input type="file" name="fileUpload1">
		<input name="btnCreate" type="button" value="+" onClick="JavaScript:fncCreateElement();">
		<input name="btnDelete" type="button" value="-" onClick="JavaScript:fncDeleteElement();"><br>	
		<span id="mySpan"></span>
		<input name="hdnLine" type="hidden" value="1">
		<input name="btnSubmit" type="submit" value="Submit">
	</form>
</body>
</html>


PHP CODE
<?php ob_start(); ?>
<html>
<head>
<title>Multible Upload & Resize</title>
</head>
<body>
	<?php
		$strConn = new COM("ADODB.Connection") or die("Cannot start ADO");
		$strConn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("db/db_main.mdb"));

		for($j=1;$j<=(int)($_POST["hdnLine"]);$j++)
		{
			if($_FILES["fileUpload".$j]["name"] != "")
			{
				$sql = "select * from count";
				$objRec = $strConn->Execute($sql);
				$i = $objRec->Fields["num"]->Value + 1 ;
				$sql = "update count set num=$i";
				$strConn->Execute($sql);
				$s_pic = "Thumbnails_".$i."_".$_FILES["fileUpload".$j]["name"];
				$l_pic = $i."_".$_FILES["fileUpload".$j]["name"];
				$sql = "insert into picture (s_picture,l_picture) values ('$s_pic','$l_pic')";
				$strConn->Execute($sql);
				
				$images = $_FILES["fileUpload".$j]["tmp_name"];
				$new_images = "Thumbnails_".$i."_".$_FILES["fileUpload".$j]["name"];
				copy($_FILES["fileUpload".$j]["tmp_name"],"MyResize/".$i."_".$_FILES["fileUpload".$j]["name"]);
				$width=100; //*** Fix Width & Heigh (Autu caculate) ***//
				$size=GetimageSize($images);
				$height=round($width*$size[1]/$size[0]);
				$images_orig = ImageCreateFromJPEG($images);
				$photoX = ImagesX($images_orig);
				$photoY = ImagesY($images_orig);
				$images_fin = ImageCreateTrueColor($width, $height);
				ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photoX, $photoY);
				ImageJPEG($images_fin,"MyResize/thumbnails/".$new_images);
				ImageDestroy($images_orig);
				ImageDestroy($images_fin);
			}
		}

		$strConn->Close();
		$strConn = null;
		
		header("Location: multi_slide.php");
	?>

</body>
</html>
<?php ob_end_flush() ; ?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-01-25 16:00:09 By : lightkung
 


 

No. 8

Guest


รบกวนถามหน่อยนะคับ พอดีไม่รู้เรื่องไรเลย

Code (PHP)
for($i=0;$i<count($_FILES["fileUpload"]["name"]);$i++)
	{
		if(trim($_FILES["fileUpload"]["tmp_name"][$i]) != "")



จากโค้ด2บรรทัดนี้ ที่
["fileUpload"]
["name"]
["tmp_name"]

มันคืออะไรหรอคับ เป็นคำสั่งหรือฟังก์ชัน หรือว่าชื่อ ไฟล์ อ่ะ คือผมอยากรู้อ่ะคับ ก้อเลยสงสัย^^

ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-08 15:20:33 By : ^^
 


 

No. 9



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
จากโค้ด2บรรทัดนี้ ที่
["fileUpload"]
["name"]
["tmp_name"]

มันคืออะไรหรอคับ เป็นคำสั่งหรือฟังก์ชัน หรือว่าชื่อ ไฟล์ อ่ะ คือผมอยากรู้อ่ะคับ ก้อเลยสงสัย^^

ขอบคุณครับ


Go to : PHP File ($_FILES,$HTTP_POST_FILES)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-08 15:30:03 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Insert และ Update รูป... Rename,Resize แบบมี Thumb เห็นถามกันบ่อยเลยเอามาลงให้ครับ...
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่