Results 1 to 30 of 30

Thread: Storing a graphic to a database via an ASP

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    7

    Storing a graphic to a database via an ASP

    Urgent query on VBscripting and databases..

    Ive got an asp that allows user to enter certain records into a ms access database. Pretty standard stuff. However, i also have to allow these users to store graphic files along with their records.

    Its like this.. On my website, a user has an equipment for sale and enters its description and price so that it can be displayed to other users (via a table display of the equipment records in my database).

    How do i also allow other users to see a picture of the equipment that the original user had posted? Is there a way to link a record in a database (ms access) to a graphic file (*.bmp) ? Im totally new at all this and i need all the help i can get

    *i hope i dont sound too confusing*


  2. #2
    Lively Member
    Join Date
    Nov 2000
    Location
    Pakistan
    Posts
    80
    Hi

    this is easy but you got to do few things for that.

    1. in you database add a field for graphics file name.
    2. add a file field in your form from which user can upload picture.


    when ever a user submit this form all the information like his name ..... , graphics file what ever (jpeg, gif, or bmp) will be submitted in your databse. like
    the graphics file will store in a specif folder (which you got to define).
    and also the name of this graphics file will add in your database with the user information.


    i think it help.

    but if you have still some problem and you want complete code for that then let me know.



    Adeel Ahmed

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    7

    Thanks for replying :)

    Ok i get the idea.. So i store the address of the stored graphic in a database and store the graphics in a specified folder.. How do u write the code for the Uploading?
    The complete code would be really helpful, thanks cuz im still stuck on it..

  4. #4
    Lively Member
    Join Date
    Nov 2000
    Location
    Pakistan
    Posts
    80
    Hi

    for uploading a file using ASP u got to use a third party software

    plz visit http://www.softartisans.com
    for free evaluation softwares



    i've attached a file by which u can get a better idea abt How u can retrieve a picture from database with the userinfor who has uploaded it.



    Adeel Ahmed

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    7

    Thanks!

    Thank you so much for your help

    Though is there a way not to do it without unsing the uploading software from softartisans?

  6. #6
    Mahfooz
    Guest
    You can upload file to the specific folder at the server using pure asp code .. no third party control is needed. If you need it, i can send you the code.

  7. #7
    Lively Member
    Join Date
    Nov 2000
    Location
    Pakistan
    Posts
    80
    hiya

    Kornifica

    you can absolutely upload a file without using any 3rd pary tool


    visit this url to get whole code!!!

    http://msdn.microsoft.com/library/en...asp?frame=true



    Adeel Ahmed

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    7

    it has to be purely ASp

    thanks guys for the help
    mahfooz.. can i take a look at your code too?

  9. #9
    CMangano
    Guest
    Here is a link to an ASP upload script:

    Pure ASP Upload Script

  10. #10
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    man, people ask this question all the time...we need a faq

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  11. #11
    Fanatic Member eimroda's Avatar
    Join Date
    Jul 2000
    Location
    Philippines
    Posts
    642
    here, you can use this pure ASP code to upload files.... I got this from one of the articles in a vb website (sorry i forgot where i get it)... it works... i have already tried it!
    On Error GoTo Hell

    Hell:
    Kill Me


    Food For Thought:

    - Do not judge a book... if you're not a judge!


  12. #12
    Hyperactive Member jovton's Avatar
    Join Date
    Nov 2000
    Location
    South Africa
    Posts
    266
    Originally posted by CMangano
    Here is a link to an ASP upload script:

    Pure ASP Upload Script
    Uhhhhhhmmmmmmm.... where's the library?
    jovton

  13. #13
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    here's one that works for sure

    i am using it in 3 site at the moment

    jus don't forget to your form to

    enctype="multipart/form-data" ACTION="upLoad.asp" METHOD="POST"

    and another thing, with this code, you can use request(""),

    because in vbscrpt after you use Request.BinaryRead
    you can user the request collection no more!!

    here the code for upload
    Code:
    <!--#INCLUDE FILE="uploadFunctions.asp" -->
    <%
        Dim tBytes
        Dim binData
        Dim Dict
        Dim fileName
        Dim fso
        Dim fsoFile
        Dim binaryFileContent
        Dim i
    
        tBytes = Request.TotalBytes
        binData = Request.BinaryRead(tBytes)
        Set Dict = BuildUploadRequest(binData)
        fileName = Dict.Item("fName").Item("FileName")
        binaryFileContent = Dict.Item("fName").Item("Value")
        fileName = ParseFileFromPath(fileName)
        picName=fileName
        fileName = Server.MapPath("../images/shirt/big/" & fileName)
        session("resumePath")=fileName
        '==constructing the filepath of the root
        '     on server 
        Set fso = Server.CreateObject("Scripting.FileSystemObject")
        Set fsoFile = fso.CreateTextFile(fileName, True)
        For i = 1 To LenB(binaryFileContent)
        fsoFile.Write Chr(AscB(MidB(binaryFileContent, i, 1)))
        Next 
        fsoFile.Close
        Set fso = Nothing
        '====== You are done!
        '====== You should have read/write permi
        '     ssions for the server directory where yo
        '     u save your file
    here's the upload functions

    Code:
    <%
        function getString(StringBin)
        getString =""
        For intCount = 1 To LenB(StringBin)
        getString = getString & chr(AscB(MidB(StringBin,intCount,1))) 
        Next
        End function
        
        function getByteString(StringStr)
        For i = 1 To Len(StringStr)
        char = Mid(StringStr, i, 1)
        getByteString = getByteString & chrB(AscB(char))
        Next
        End function
        
        function BuildUploadRequest(RequestBin)
        	Dim scrDict
        	Set scrDict = Server.CreateObject("Scripting.Dictionary")
        PosBeg = 1
        PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
        boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
        boundaryPos = InstrB(1,RequestBin,boundary)
        Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
        Dim UploadControl
        Set UploadControl = CreateObject("Scripting.Dictionary")
        Pos = InstrB(BoundaryPos,RequestBin, getByteString("Content-Disposition"))
        Pos = InstrB(Pos,RequestBin,getByteString("name="))
        PosBeg = Pos+6
        PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
        Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        PosFile=InstrB(BoundaryPos,RequestBin,getByteString("filename="))
        PosBound = InstrB(PosEnd,RequestBin,boundary)
        if PosFile<>0 AND (PosFile<PosBound) Then
        			PosBeg = PosFile + 10
        			PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
        			FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        			UploadControl.Add "FileName", FileName
        			Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
        			PosBeg = Pos+14
        			PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
        			ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        			UploadControl.Add "ContentType",ContentType
        			PosBeg = PosEnd+4
        			PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
        			Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
        	Else
        			Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
        			PosBeg = Pos+4
        			PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
        			Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
        	End if
        		UploadControl.Add "Value" , Value
        		scrDict.Add Name, UploadControl
        BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
        Loop
        	
        	Set BuildUploadRequest = scrDict
        	Set scrDict = Nothing
        	
        End function
        
        function ParseFileFromPath(iStr)
        Dim tPos
        tPos = InStrRev(iStr, "\")
        if tPos = 0 Or IsNull(tPos) Then
        ParseFileFromPath = iStr
        Exit function
        End if
        ParseFileFromPath = Right(iStr, Len(iStr) - tPos)
        End function
        %>

  14. #14
    CMangano
    Guest
    Very bottom of the article:

    "You can download the library and sample files here"

  15. #15
    Hyperactive Member jovton's Avatar
    Join Date
    Nov 2000
    Location
    South Africa
    Posts
    266
    I know, coz I have downloaded it, but the zip does not contain any library files in it. Only asp, txt, and htm files. no dll, no nottin.

    Have I perhaps downloaded the wrong file? Heheheh. Maybe.
    But no, I'm sure that its the right file. Yes. it must be, coz, it is the same url you gave me.
    jovton

  16. #16
    CMangano
    Guest
    It is a pure ASP script, no dlls.

  17. #17
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    thanks for that upload, i have been wanting one of those for a long time

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  18. #18
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    You all should go to stardeveloper.com/databases.asp
    This dude has a shtload of cool examples including one that uploads the picture directly to the database.
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  19. #19
    CMangano
    Guest
    Personally I don't feel that images should be stored directly in the database. I prefer to store the path to the image, then store the image on the file server.

    I will take a look at the site though, always looking for new information

  20. #20
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    Can the picture reside in the web server by itself or must I hace a file server?
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  21. #21
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    ok I have tried the 2 downloads that are posted here and all that happens when I try to upload on my local machine is that the page hangs...

    any ideas?

  22. #22
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    mine works jesus4u!!change

    fileName = Server.MapPath("../images/shirt/big/" & fileName)

    to a valid path

    that is the one i use on our site to upload resume

  23. #23
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    ok I didn't use yours cause I am a simple man and I didn't see the interface but I will give it a go!

  24. #24
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    sebs is ur code posting to itself or do I create another page?

  25. #25
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    well,
    in total there is 3 pages,

    one with your form(with the upload button)
    one that your form is submitted to,
    and a third one(asp functions) that is included in the previous one,
    so you only see one,

    but if you want , you can make it submit to itself, no problemo!

    hope it help you, if you have any problem just ask,
    cause it work perfectly,i use it in 3 site at this moment!!

    see ya!

  26. #26
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216
    thanks

  27. #27
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    OK I want to do what is said above and have the picture in a folder but the path in a database. If the visitor uploads the picture, how do I 'grab' the filename and store in in the database?
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  28. #28
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    if you take my mine,


    this line is your filename
    fileName = ParseFileFromPath(fileName)

    here the file path, you can put your own, just make the folder before
    fileName = Server.MapPath("../images/shirt/big/" & fileName)

  29. #29
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    No, what I meant was, that the picture is stored on a folder but I want the name of the picture, for example "pic23.gif" to be stored in a database field, so then I can reference to it.
    Top Tip: You can make friends and impress the opposite sex at geeky cocktail parties by saying "DB" instead of database. - Karl Moore

  30. #30
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    don't forget to put this to your form

    enctype="multipart/form-data"

    and it should work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width