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 > ASP > ASP Image > ASP Resize Image and Insert to Database



Clound SSD Virtual Server

ASP Resize Image and Insert to Database

ASP Resize Image and Insert to Database เขียน ASP ในการ Upload ไฟล์ และทำการ Resize ก่อนเก็บลงใน Database ในรูปแบบของ Thumbnails โดยทำการแสดงไฟล์ที่เป็น Thumbnails เมื่อคลิกที่รูปก็จะทำการเปิดไฟล์ต้นฉบับ วิธีนี้ช่วยลดขนาดของการ Transfer Bandwidth ได้ด้วยครับ

ASP aspSmartUpload



Syntax

Server.CreateObject("OWC10.ChartSpace")



AspUploadResize1.html

<html>
<head>
<title>ThaiCreate.Com ASP & Upload Resize</title>
</head>
<body>
<form action="AspUploadResize2.asp" method="post" enctype="multipart/form-data" name="frmMain">
Upload 
<input name="file1" type="file">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>


AspUploadResize2.asp

<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & Upload Resize</title>
</head>
<body>
<%
	Dim mySmartUpload
	Dim Conn,strSQL,objExec

	'*** Create Object ***'	
	Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

	'*** Upload Files ***'
	mySmartUpload.Upload
	
	Dim sFileName,strPath
	strPath = "MyResize"
	sFileName = mySmartUpload.Files("file1").FileName

	'*** Upload file1 ***'
	If mySmartUpload.Files("file1").FileName <> "" Then
		mySmartUpload.Files("file1").SaveAs(Server.MapPath(strPath & "/" & sFileName))
		Response.write sFileName & " Resize Successful.<br>"

		'*** Resize Images ***'

		Dim Chs, objConst,NewWidth,NewHeight
		Dim OutFormat,OutFileName
		OutFormat = "Jpg" '*** Gif,Png ***'
		OutFileName = "Thumbnails_"&sFileName
		NewWidth = "100" '*** Set new Width , Height automatic caculate ***'
		NewHeight = 0 '*** Auto Resize ***'
		 
		'*** Get Images Width & Height ***'
		Dim objFso,myImg,Width,Height
		Set objFso = Server.CreateObject("Scripting.FileSystemObject")
		IF objFso.FileExists(Server.MapPath(strPath&"/"&sFileName))  Then	
			set myImg = Loadpicture(Server.MapPath(strPath&"/"&sFileName))
			Width = Round(myImg.width / 26.4583)
			Height = Round(myImg.height / 26.4583)
			NewHeight = Round((NewWidth*Height)/Width)
			'NewHeight = 100
			'NewWidth = Round((NewHeight*Width)/Height) '*** or Automatic Height ***'
		End If
		'*************** End *************'

		Set Chs = Server.CreateObject("OWC10.ChartSpace") 
		Set objConst = Chs.Constants  
		 
		Chs.Interior.SetTextured Server.MapPath(strPath&"/"&sFileName), objConst.chStretchPlot, , objConst.chAllFaces  
		Chs.border.color = -3  

	   'Chs.border.color = &H0000FF  
	   'Chs.border.Weight = 3  

		Chs.ExportPicture Server.MapPath(strPath&"/"&OutFileName),OutFormat,NewWidth,NewHeight
		
		Set objConst = Nothing
		Set Chs = Nothing

		'*** Insert Record ***'	
		Set Conn = Server.Createobject("ADODB.Connection")
		Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
		strSQL = ""
		strSQL = strSQL &"INSERT INTO files "
		strSQL = strSQL &"(Thumbnails,FilesName) VALUES ('"&OutFileName&"','"&sFileName&"')"
		Set objExec = Conn.Execute(strSQL)

	End If

	Response.write("<a href=AspUploadResize3.asp>View files</a>")


	Set mySmartUpload = Nothing
%>
</body>
</html>


AspUploadResize3.asp

<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & Upload Resize</title>
</head>
<body>
	<%
	Dim Conn,strSQL,objRec
	Set Conn = Server.Createobject("ADODB.Connection")
	Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("mydatabase.mdb"),"" , ""
	strSQL = "SELECT * FROM files "
	Set objRec = Server.CreateObject("ADODB.Recordset")
	objRec.Open strSQL, Conn, 1,3
	%>
	<table width="200" border="1">
	<tr>
	<th width="50"> <div align="center">Files ID </div></th>
	<th width="150"> <div align="center">Resize </div></th>
	</tr>
	<%
	While Not objRec.EOF
	%>
	<tr>
	<td><div align="center"><%=objRec.Fields("FilesID").Value%></div></td>
	<td><center>
	<a href="MyResize/<%=objRec.Fields("FilesName").Value%>">

	<img src="MyResize/<%=objRec.Fields("Thumbnails").Value%>" border="0"></a></center>
	</td>
	</tr>
	<%
	objRec.MoveNext
	Wend
	%>
	</table>
	<%

	objRec.Close()
	Conn.Close()
	Set objRec = Nothing
	Set Conn = Nothing
	%>
	<br>
	<a href="AspUploadResize1.html">New Upload</a>
</body>
</html>

Screenshot

ASP & Upload Resize

ASP & Upload Resize

ASP & Upload Resize

ASP & Upload Resize

ASP & Upload Resize






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2008-10-23 16:00:04 / 2009-02-01 09:26:46
  Download : Download  ASP Resize Image and Insert to Database
 Sponsored Links / Related

 
ASP Create Image
Rating :

 
ASP Write Text in Image
Rating :

 
ASP Resize Image
Rating :

 
ASP Upload and Resize Image
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 01
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 อัตราราคา คลิกที่นี่