Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store an image path in the database and more

Status
Not open for further replies.

iwan1981

Technical User
Oct 15, 2002
8
0
0
NL
Hi I have discoverd how i can upload an image to an webserver folder.
Now if i upload the file it is being with this code: (UPLOAD.ASP)

<%
Option Explicit

Dim SAVEPATH
SAVEPATH = Server.MapPath(&quot;/IMAGES/uploaded/&quot;)

Dim oUpload, oFile
Dim strPath, strFile, strExt, strType

'Maak object, let op het New command ipv Server.CreateObject
Set oUpload = Server.CreateObject(&quot;Dundas.Upload.2&quot;)
oUpload.MaxUploadSize = 100000
'oUpload.UseVirtualDir = True
oUpload.UseUniqueNames = True

Set oFile = oUpload.GetNextFile()

If InStr(1,oFile.ContentType,&quot;image&quot;) Then
oFile.Save(SAVEPATH)
Response.Write(oFile.FileName)
End If

Set oFile = Nothing
Set oUpload = Nothing
%>

Now if i upload an image with an other form that looks like this :UPLOADFORM.ASP

<html>
<head>
<TITLE>Bestand</TITLE>
</head>
<body BGCOLOR=&quot;#cccccc&quot;>
<form METHOD=&quot;POST&quot; ENCTYPE=&quot;multipart/form-data&quot; ACTION=&quot;upload.asp&quot;>
Bestand: <input TYPE=&quot;FILE&quot; NAME=&quot;bestand&quot; ACCEPT=&quot;image/gif,image/jpeg&quot;><br>
<input TYPE=&quot;SUBMIT&quot; VALUE=&quot;Stuur bestand&quot;>
</form>
</body>
</html>

The filename gets a name that looks like this:
{812026AA-D69E-4676-BD18-01FDB7AD0BA0}_105535716.jpg

What i want to do is store this to somebody's recordset with the name of the picture and the ClassID.

I also need to know how i should recall the picture ...so if an user has uploaded a picture with his regestration ...he can log in again and should be able to see a picture with the userdata of the user.

Can someone help me with this ...because i am not that familier with ASP.

Thank you!
 
Well you can create an additional ariable in your first script to store the filename (oFile.FileName) and then use that to insert into your db:
Code:
<%
Option Explicit

Dim SAVEPATH
SAVEPATH = Server.MapPath(&quot;/IMAGES/uploaded/&quot;)

Dim oUpload, oFile
Dim strPath, strFile, strExt, strType
Dim picFilename   'new variable

'Maak object, let op het New command ipv Server.CreateObject
Set oUpload = Server.CreateObject(&quot;Dundas.Upload.2&quot;)
oUpload.MaxUploadSize = 100000
'oUpload.UseVirtualDir = True
oUpload.UseUniqueNames = True

Set oFile = oUpload.GetNextFile()

If InStr(1,oFile.ContentType,&quot;image&quot;) Then
    oFile.Save(SAVEPATH)
    Response.Write(oFile.FileName)
    picFilename = &quot;oFile.FileName&quot;
End If

Set oFile = Nothing
Set oUpload = Nothing

'do you database stuff here. Use the picFilename variable to store the image filename, use SAVEPATH for the path.
%>
<!-- To Display Image -->
<img src=&quot;<%=SAVEPATH&picFIlename%>&quot;>

I displayed the image using the variables, but once it is in the datbase you can write the path from the database into the same place and the image will display.

Hope that helps,
-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top