Hello all, im very newbie in asp code and now im having a project which needed to use ASP code, as for now i get the upload code from freaspupload website while it only upload to folder and im not sure how to store the image name into my database so later on i able to retrieve it in my website. The coding is as below. - <%@ Language=VBScript %>
-
-
<%
-
option explicit
-
Response.Expires = -1
-
Server.ScriptTimeout = 600
-
-
-
%>
-
[bad html removed] #include file="freeaspupload.asp" -->
-
[bad html removed] #include file="dbconnection.asp" -->
-
<%
-
-
-
' ****************************************************
-
' Change the value of the variable below to the pathname
-
' of a directory with write permissions, for example "C:\Inetpub\wwwroot"
-
Dim uploadsDirVar
-
uploadsDirVar = "c:\inetpub\wwwroot\mmutrolley\upload"
-
' ****************************************************
-
-
' Note: this file uploadTester.asp is just an example to demonstrate
-
' the capabilities of the freeASPUpload.asp class. There are no plans
-
' to add any new features to uploadTester.asp itself. Feel free to add
-
' your own code. If you are building a content management system, you
-
' may also want to consider this script: http://www.webfilebrowser.com/
-
-
function OutputForm()
-
%>
-
<form name="frmSend" method="POST" enctype="multipart/form-data" action="uploadTester.asp" onSubmit="return onSubmitForm();">
-
<B>File names:</B><br>
-
File : <input name="attach1" type="file" size=35><br>
-
<br>
-
-
<input style="margin-top:4" type=submit value="Upload">
-
</form>
-
<%
-
end function
-
-
function TestEnvironment()
-
Dim fso, fileName, testFile, streamTest
-
TestEnvironment = ""
-
Set fso = Server.CreateObject("Scripting.FileSystemObject")
-
if not fso.FolderExists(uploadsDirVar) then
-
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
-
exit function
-
end if
-
fileName = uploadsDirVar & "\test.txt"
-
on error resume next
-
Set testFile = fso.CreateTextFile(fileName, true)
-
If Err.Number<>0 then
-
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open uploadTester.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
-
exit function
-
end if
-
Err.Clear
-
testFile.Close
-
fso.DeleteFile(fileName)
-
If Err.Number<>0 then
-
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
-
exit function
-
end if
-
Err.Clear
-
Set streamTest = Server.CreateObject("ADODB.Stream")
-
If Err.Number<>0 then
-
TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
-
exit function
-
end if
-
Set streamTest = Nothing
-
end function
-
-
function SaveFiles
-
Dim Upload, fileName, fileSize, ks, i, fileKey
-
-
Set Upload = New FreeASPUpload
-
Upload.Save(uploadsDirVar)
-
-
' If something fails inside the script, but the exception is handled
-
If Err.Number<>0 then Exit function
-
-
SaveFiles = ""
-
ks = Upload.UploadedFiles.keys
-
if (UBound(ks) <> -1) then
-
SaveFiles = "<B>Files uploaded:</B> "
-
for each fileKey in Upload.UploadedFiles.keys
-
SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
-
next
-
else
-
SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
-
end if
-
end function
-
%>
-
-
<HTML>
-
<HEAD>
-
<TITLE>Test Free ASP Upload 2.0</TITLE>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<style>
-
BODY {background-color: white;font-family:arial; font-size:12}
-
</style>
-
<script>
-
function onSubmitForm() {
-
var formDOMObj = document.frmSend;
-
if (formDOMObj.attach1.value == "" && formDOMObj.attach2.value == "" && formDOMObj.attach3.value == "" && formDOMObj.attach4.value == "" )
-
alert("Please press the Browse button and pick a file.")
-
else
-
return true;
-
return false;
-
}
-
</script>
-
-
</HEAD>
-
-
<BODY>
-
-
<br><br>
-
<div style="border-bottom: #A91905 2px solid;font-size:16">Upload files to your server</div>
-
<%
-
Dim diagnostics
-
if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
-
diagnostics = TestEnvironment()
-
if diagnostics<>"" then
-
response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
-
response.write diagnostics
-
response.write "<p>After you correct this problem, reload the page."
-
response.write "</div>"
-
else
-
response.write "<div style=""margin-left:150"">"
-
OutputForm()
-
response.write "</div>"
-
end if
-
else
-
response.write "<div style=""margin-left:150"">"
-
OutputForm()
-
response.write SaveFiles()
-
response.write "<br><br></div>"
-
end if
-
-
%>
-
-
-
-
-
</BODY>
-
</HTML>
4 3675
Near the bottom of the page, there is a line that says "response.write savefiles()" if you want to store the file name in the db, you should that value in the db. Do you know how to update dbs in general? If so, the line might look something like this: - objRS("filePath") = saveFiles()
If you need help updating your db, please ask.
Jared
Thanks alot for your reply...update database in normal ASP coding im ok, but for this VBscript im not sure,i try a few time and fail.Currenly i have a dbconnection.asp to connect database, the code for it is -
<%
-
-
dim connDB
-
Set connDB = Server.CreateObject("ADODB.Connection")
-
connDB.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("mmutrolley.mdb") & ";Persist Security Info=False"
-
-
%>
-
can you help me abit in updating? Really thanks alot..
@k1d0
sorry for the delay, I thought I had replied to you earlier. Try this: - dim connDB, objRS
-
Set connDB = Server.CreateObject("ADODB.Connection")
-
connDB.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("mmutrolley.mdb") & ";Persist Security Info=False"
-
set objRS = server.createobject("adodb.recordset")
-
objRS.open "SELECT * FROM myTable", connDB, adopendynamic, adlockoptimistic
-
-
objRS.addNew()
-
objRS("filePath") = saveFiles()
-
objRS.update
-
Just a couple things to note:
1- adopendynamic are constants, you might need to set those, they should be 3 and 2 I believe, but you can look them up to make sure
2- between addNew and update you can set any field value on that row of the table. Does this make sense?
Jared
Solved - Imports System.Data.SqlClient
-
Imports System.Data
-
Imports System.IO
-
-
Public Class Form1
-
Dim str As String = "Data Source=NET3\SQLEXPRESS;Initial Catalog=RestPos;Persist Security Info=True;User ID=sa;Password=password"
-
Dim con As New SqlClient.SqlConnection
-
-
'To open an image from computer
-
'-------------------------------
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
-
OpenFileDialog1.Title = "Please select a file"
-
OpenFileDialog1.InitialDirectory = "c:temp"
-
OpenFileDialog1.ShowDialog()
-
TextBox2.Text = OpenFileDialog1.FileName.ToString '--->To Show the file path in textbox2
-
PictureBox1.ImageLocation = TextBox2.Text '--->To show selected image in picturebox
-
End sub
-
-
'To insert selected image into database
-
'The datatype of the column in table to store image should be <image>
-
'--------------------------------------------------------------------
-
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
-
con.ConnectionString = str
-
Dim ms As New IO.MemoryStream()
-
PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
-
Dim arrimage() As Byte = ms.GetBuffer
-
Dim cmd As New SqlCommand("insert into image (Emp_Image)values(@picture)", con)
-
cmd.Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrimage
-
con.Open()
-
cmd.ExecuteNonQuery()
-
con.Close()
-
End Sub
-
-
'We have successfully inserted the image into database.
-
'Now we want to Retrieve the image from database.
-
'-------------------------------------------------
-
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
-
Dim stream As New IO.MemoryStream()
-
con.Open()
-
Dim command As New SqlCommand("select Emp_Image from Image where Emp_Id='" + TextBox3.Text + "'", con) '--->You can give Emp_id instead of Textbox value.
-
Dim image As Byte() = DirectCast(command.ExecuteScalar(), Byte())
-
stream.Write(image, 0, image.Length)
-
con.Close()
-
Dim bitmap As New Bitmap(stream)
-
PictureBox2.Image = bitmap '--->I have used another picturebox to display image from database.
-
End Sub
-
'Thats all, You can place a linklabel below the picturebox if you to change photo and update it in database.
Regards,
Prathap
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bissatch |
last post by:
Hi,
I am trying to write script that is run when a form is submitted. The
form contains an image input field and when submitted, the image is
uploaded, resized and added as binary information to...
|
by: Satish Appasani |
last post by:
Hi:
I have a ASP.NET form with Web layout which I've achieved using panels. In
one of the tab I have a File control to upload Images. When I put a file in
the file control and move to another...
|
by: IkBenHet |
last post by:
Hello,
I use this script to upload image files to a folder on a IIS6 server:
******************* START UPLOAD.ASPX FILE **********************
<%@ Page Language="VB" Debug="true" %>
|
by: moondaddy |
last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data.
one data item I need to store is an image the user uploaded. My problem is
that I don't know how to get the image into...
|
by: Brad |
last post by:
I have code which takes an image, uploaded from a web page, and saves it to
a database. Now I want to always resize an uploaded image before it is
saved to the database. My code to resize is...
|
by: RedHair |
last post by:
I'd like to set up a file system for the ASP.NET 2.0 application
to store user-uploaded files, since the members are more than
100,000 people, the basic requirements are as below:
(1) The file...
|
by: ctiggerf |
last post by:
I was hopeing someone could help me out here. Been stumped on this
one all day.
This function
1. Checks uploaded files.
2. Creates two resized images from each (a full size, and a...
|
by: harshad |
last post by:
Dear All,Here I am facing problem to store image.I am trying to store byte
array(image) in to session variable so at time of update I will got that
byte array and I do my update. here i am given...
|
by: sejal17 |
last post by:
hi all,
To upload image i want to make an folder of username using which user is login and put image in that folder
thanks
|
by: ahilar12 |
last post by:
Hi experts,
I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |