Print Page | Close Window

Get the full path to a file in a database

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=2666
Printed Date: 29 March 2026 at 7:40pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Get the full path to a file in a database
Posted By: eagle00789
Subject: Get the full path to a file in a database
Date Posted: 13 May 2003 at 9:34am

I am creating a mod for my forum wich get's an image out of a database and place a link (or the image itself) in the IE_editor, but when i run the test, i get a link back that looks like http://www.mysite/imagefileID=34 - http://www.mysite/imagefileID=34
while it has to be
http://www.mysite.com/image/file.asp?ID=34 - http://www.mysite.com/image/file.asp?ID=34

below are the files in seperate posts

You can download a full featured zipfile containing all the neccesary files http://members.home.nl/chris.simon/wwf/wwwroot.zip - here

If you want to see it for your self, then just go http://217.121.39.22/forum/forumrc1/default.asp - here  and place a message in the forum with an image from the new button that is there. see the post that is already there to see for your self

can anybody help me



-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here



Replies:
Posted By: eagle00789
Date Posted: 13 May 2003 at 9:35am

file.asp

----

<%
 ' -- file.asp --
 ' Retrieves binary files from the database
 
 Response.Buffer = True
 
 ' ID of the file to retrieve
 Dim ID
  ID = Request("ID")
  
 If Len(ID) < 1 Then
  ID = 7
 End If
 
 ' Connection String
 Dim connStr
  connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("FileDB.mdb")
 
 ' Recordset Object
 Dim rs
  Set rs = Server.CreateObject("ADODB.Recordset")
  
  ' opening connection
  rs.Open "select [File Data],[Content Type] from Files where ID = " & ID, connStr, 2, 4

  If Not rs.EOF Then
   Response.ContentType = rs("Content Type")
   Response.BinaryWrite rs("File Data")
  End If
  
  
  rs.Close
  Set rs = Nothing
%>

----



-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here


Posted By: eagle00789
Date Posted: 13 May 2003 at 9:36am

IE_Image_Database

----

<html>
<head>
<title>Plaatjes & foto's</title>
'this is the function to get the path
<script  language="JavaScript">
function CopyPost()
{
  document.frames.bron.document.execCommand("SelectAll",false);
 document.frames.bron.document.execCommand("Copy",false);
 window.opener.frames.message.focus();       
 window.opener.frames.message.document.execCommand("Paste",false);
 window.close();
}
</script>
</head>

<body>
 <center><H3>Kies het gewenste plaatje / foto</H3></center>
<hr>
<center><iframe name="bron" src="show.asp" width="725" height="250" marginwidth="1" marginheight="1">
sorry no Iframe support</iframe></center>
<hr>
<div align="center">
  <center>
  <table border="4" cellpadding="2" style="border-collapse: collapse" bordercolor="#800000" id="AutoNumber1" bgcolor="#FFCC00">
    <tr>
      <td width="150" align="center"><a href="JavaScript:onClick=CopyPost()" style="text-decoration: none"><b>Invoegen</b></a></td>
      <td width="400" align="center"><a href="JavaScript:onClick=history.back()" style="text-decoration: none"><b> - Terug naar lijst - </b></a></td>
      <td width="150" align="center"><a href="JavaScript:onClick=window.close()" style="text-decoration: none"><b>Anuleer</b></a></td>
    </tr>
  </table>
  </center>
</body>
</html>

----



-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here


Posted By: eagle00789
Date Posted: 13 May 2003 at 9:39am

insert.asp

----

<!--#include file="Loader.asp"-->
<%
 Response.Buffer = True

 ' load object
 Dim load
  Set load = new Loader
  
  ' calling initialize method
  load.initialize
  
 ' File binary data
 Dim fileData
  fileData = load.getFileData("file")
 ' File name
 Dim fileName
  fileName = LCase(load.getFileName("file"))
 ' File path
 Dim filePath
  filePath = load.getFilePath("file")
 ' File path complete
 Dim filePathComplete
  filePathComplete = load.getFilePathComplete("file")
 ' File size
 Dim fileSize
  fileSize = load.getFileSize("file")
 ' File size translated
 Dim fileSizeTranslated
  fileSizeTranslated = load.getFileSizeTranslated("file")
 ' Content Type
 Dim contentType
  contentType = load.getContentType("file")
 ' No. of Form elements
 Dim countElements
  countElements = load.Count
 ' Value of text input field "fname"
 Dim fnameInput
  fnameInput = load.getValue("fname")
 ' Value of text input field "lname"
 Dim lnameInput
  lnameInput = load.getValue("lname")
 ' Value of text input field "profession"
 Dim profession
  profession = load.getValue("profession") 
  
 ' destroying load object
 Set load = Nothing
%>

<html>
<head>
 <title>Plaatjes toevoegen aan de database</title>
 <style>
  body, input, td { font-family:verdana,arial; font-size:10pt; }
 </style>
</head>
<body>
 <p align="center">
  <b>Binare data toevoegen aan de database</b><br>
  <a href="show.asp">Klik hier om de ingevoegde data te zien</a>
 </p>
 
 <table width="700" border="1" align="center">
 <tr>
  <td>Bestandsnaam</td><td><%= fileName %></td>
 </tr><tr>
  <td>Bestandspad</td><td><%= filePath %></td>
 </tr><tr>
  <td>Compleet bestandspad</td><td><%= filePathComplete %></td>
 </tr><tr>
  <td>Bestandsgrote</td><td><%= fileSize %></td>
 </tr><tr>
  <td>Vertaalde bestandsgrote</td><td><%= fileSizeTranslated %></td>
 </tr><tr>
  <td>Inhoudstype</td><td><%= contentType %></td>
 </tr><tr>
  <td>Aantal formulierelementen</td><td><%= countElements %></td>
 </tr><tr>
  <td>Voornaam</td><td><%= fnameInput %></td>
 </tr><tr>
  <td>Achternaam</td><td><%= lnameInput %></td>
 </tr>
 <tr>
  <td>Beroep</td><td><%= profession %></td>
 </tr>
 </table><br><br>
 
 <p style="padding-left:220;">
 <%= fileName %> data ontvangen ...<br>
 <%
  ' Checking to make sure if file was uploaded
  If fileSize > 0 Then
  
   ' Connection string
   Dim connStr
    connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("FileDB.mdb")
  
   ' Recordset object
   Dim rs
    Set rs = Server.CreateObject("ADODB.Recordset")
    
    rs.Open "Files", connStr, 2, 2
    
    ' Adding data
    rs.AddNew
     rs("File Name") = fileName
     rs("File Size") = fileSize
     rs("File Data").AppendChunk fileData
     rs("Content Type") = contentType
     rs("First Name") = fnameInput
     rs("Last Name") = lnameInput
     rs("Profession") = profession
    rs.Update
    
    rs.Close
    Set rs = Nothing
    
   Response.Write "<font color=""green"">Bestand was met succes toegevoegd aan de database...</font>"
  Else
   Response.Write "<font color=""brown"">Geen bestand was geselecteerd om te uploaden...</font>"
  End If
   
   
  If Err.number <> 0 Then
   Response.Write "<br><font color=""red"">Er ging iets fout...</font>"
  End If
 %>
 </p>
 
 <br>
 <table border="0" align="center">
 <tr>
 <form method="POST" enctype="multipart/form-data" action="Insert.asp">
 <td>Voornaam :</td><td>
  <input type="text" name="fname" size="40"></td></tr>
 <td>Achternaam :</td><td>
  <input type="text" name="lname" size="40"></td></tr>
 <td>Beroep :</td><td>
  <input type="text" name="profession" size="40" value="Developer"></td></tr>
 <td>Bestand :</td><td>
  <input type="file" name="file" size="40"></td></tr>
 <td>&nbsp;</td><td>
  <input type="submit" value="Submit"></td></tr>
 </form>
 </tr>
 </table>

</body>
</html>

----



-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here


Posted By: eagle00789
Date Posted: 13 May 2003 at 9:40am

insert.htm

----

<html>
<head>
 <title>Plaatjes toevoegen aan de database</title>
 <style>
  body, input { font-family:verdana,arial; font-size:10pt; }
 </style>
</head>
<body>
 <p align="center">
  <b>Binare data toevoegen aan de database</b><br>
  <a href="show.asp">Klik hier om de ingevoegde data te zien</a>
 </p>
 
 <table border="0" align="center">
 <tr>
 <form method="POST" enctype="multipart/form-data" action="Insert.asp">
 <td>Voornaam :</td><td>
  <input type="text" name="fname" size="40" value="Chris"></td></tr>
 <td>Achternaam :</td><td>
  <input type="text" name="lname" size="40" value="Simon"></td></tr>
 <td>Beroep :</td><td>
  <input type="text" name="profession" size="40" value="Developer"></td></tr>
 <td>Bestand :</td><td>
  <input type="file" name="file" size="40"></td></tr>
 <td>&nbsp;</td><td>
  <input type="submit" value="Submit"></td></tr>
 </form>
 </tr>
 </table>

</body>
</html>

----



-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here


Posted By: eagle00789
Date Posted: 13 May 2003 at 9:42am

loader.asp

----

<%
 
 Class Loader
  Private dict
  
  Private Sub Class_Initialize
   Set dict = Server.CreateObject("Scripting.Dictionary")
  End Sub
  
  Private Sub Class_Terminate
   If IsObject(intDict) Then
    intDict.RemoveAll
    Set intDict = Nothing
   End If
   If IsObject(dict) Then
    dict.RemoveAll
    Set dict = Nothing
   End If
  End Sub

  Public Property Get Count
   Count = dict.Count
  End Property

  Public Sub Initialize
   If Request.TotalBytes > 0 Then
    Dim binData
     binData = Request.BinaryRead(Request.TotalBytes)
     getData binData
   End If
  End Sub
  
  Public Function getFileData(name)
   If dict.Exists(name) Then
    getFileData = dict(name).Item("Value")
    Else
    getFileData = ""
   End If
  End Function

  Public Function getValue(name)
   Dim gv
   If dict.Exists(name) Then
    gv = CStr(dict(name).Item("Value"))
    
    gv = Left(gv,Len(gv)-2)
    getValue = gv
   Else
    getValue = ""
   End If
  End Function
  
  Public Function saveToFile(name, path)
   If dict.Exists(name) Then
    Dim temp
     temp = dict(name).Item("Value")
    Dim fso
     Set fso = Server.CreateObject("Scripting.FileSystemObject")
    Dim file
     Set file = fso.CreateTextFile(path)
      For tPoint = 1 to LenB(temp)
          file.Write Chr(AscB(MidB(temp,tPoint,1)))
      Next
      file.Close
     saveToFile = True
   Else
     saveToFile = False
   End If
  End Function
  
  Public Function getFileName(name)
   If dict.Exists(name) Then
    Dim temp, tempPos
     temp = dict(name).Item("FileName")
     tempPos = 1 + InStrRev(temp, "\")
     getFileName = Mid(temp, tempPos)
   Else
    getFileName = ""
   End If
  End Function
  
  Public Function getFilePath(name)
   If dict.Exists(name) Then
    Dim temp, tempPos
     temp = dict(name).Item("FileName")
     tempPos = InStrRev(temp, "\")
     getFilePath = Mid(temp, 1, tempPos)
   Else
    getFilePath = ""
   End If
  End Function
  
  Public Function getFilePathComplete(name)
   If dict.Exists(name) Then
    getFilePathComplete = dict(name).Item("FileName")
   Else
    getFilePathComplete = ""
   End If
  End Function

  Public Function getFileSize(name)
   If dict.Exists(name) Then
    getFileSize = LenB(dict(name).Item("Value"))
   Else
    getFileSize = 0
   End If
  End Function

  Public Function getFileSizeTranslated(name)
   If dict.Exists(name) Then
    temp = 1 + LenB(dict(name).Item("Value"))
     If Len(temp) <= 3 Then
      getFileSizeTranslated = temp & " bytes"
     ElseIf Len(temp) > 6 Then
      temp = FormatNumber(((temp / 1024) / 1024), 2)
      getFileSizeTranslated = temp & " megabytes" 
     Else
      temp = FormatNumber((temp / 1024), 2)
      getFileSizeTranslated = temp & " kilobytes"
     End If
   Else
    getFileSizeTranslated = ""
   End If
  End Function
  
  Public Function getContentType(name)
   If dict.Exists(name) Then
    getContentType = dict(name).Item("ContentType")
   Else
    getContentType = ""
   End If
  End Function

 Private Sub getData(rawData)
  Dim separator
   separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)

  Dim lenSeparator
   lenSeparator = LenB(separator)

  Dim currentPos
   currentPos = 1
  Dim inStrByte
   inStrByte = 1
  Dim value, mValue
  Dim tempValue
   tempValue = ""

  While inStrByte > 0
   inStrByte = InStrB(currentPos, rawData, separator)
   mValue = inStrByte - currentPos

   If mValue > 1 Then
    value = MidB(rawData, currentPos, mValue)

    Dim begPos, endPos, midValue, nValue
    Dim intDict
     Set intDict = Server.CreateObject("Scripting.Dictionary")
  
     begPos = 1 + InStrB(1, value, ChrB(34))
     endPos = InStrB(begPos + 1, value, ChrB(34))
     nValue = endPos

    Dim nameN
     nameN = MidB(value, begPos, endPos - begPos)

    Dim nameValue, isValid
     isValid = True
     
     If InStrB(1, value, stringToByte("Content-Type")) > 1 Then

      begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
      endPos = InStrB(begPos + 1, value, ChrB(34))
 
      If endPos = 0 Then
       endPos = begPos + 1
       isValid = False
      End If
      
      midValue = MidB(value, begPos, endPos - begPos)
       intDict.Add "FileName", trim(byteToString(midValue))
        
      begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
      endPos = InStrB(begPos, val

-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here



Posted By: eagle00789
Date Posted: 13 May 2003 at 9:43am

show.asp

----

<%
 ' Generates a list of uploaded files
 
 Response.Buffer = True
 
 ' Connection String
 Dim connStr
  connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("FileDB.mdb")
%>
<html>
<head>
 <title>Plaatjes toevoegen aan de database</title>
 <style>
  body, input, td { font-family:verdana,arial; font-size:10pt; }
 </style>
</head>
<body>
 <p align="center">
  <b>Laat binare data zien uit de database</b><br>
  <a href="insert.htm">Klik hier om plaatjes toe te voegen</a>
 </p>
 
 <table width="700" border="1" align="center">
<%
 ' Recordset Object
 Dim rs
  Set rs = Server.CreateObject("ADODB.Recordset")
  
  ' opening connection
  rs.Open "select [ID],[File Name],[File Size],[Content Type],[First Name],[Last Name],[Profession] from Files order by [ID] desc", connStr, 3, 4

  If Not rs.EOF Then
   Response.Write "<tr><td colspan=""7"" align=""center""><i>"
   Response.Write "Aantal records : " & rs.RecordCount
   Response.Write ", Tabel : Bestanden</i><br>"
   Response.Write "</td></tr>"
 
   While Not rs.EOF
    Response.Write "<tr><td>"
    Response.Write rs("ID") & "</td><td>"
    Response.Write "<a href=""file.asp?ID=" & rs("ID") & """>"
    Response.Write rs("File Name") & "</a></td><td>"
    Response.Write rs("File Size") & "</td><td>"
    Response.Write rs("Content Type") & "</td><td>"
    Response.Write rs("First Name") & "</td><td>"
    Response.Write rs("Last Name") & "</td><td>"
    Response.Write rs("Profession")
    Response.Write "</td></tr>"
    rs.MoveNext
   Wend
  Else
   Response.Write "No Record Found"
  End If
  
  rs.Close
  Set rs = Nothing
%>
 </table>
</body>
</html>

----



-------------
Using forum at http://www.gravenrode.nl/forum/forum - Gravenrode and http://www.gravenrode.nl/forum/test_forum - here and http://217.121.39.22/forum/test_forum - here



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net