Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    find the location of image

    Here is my problem, I have the jpg name in the database as:
    62559_10151456622700100_611995567_n.jpg

    It is saved here:
    C:\inetpub\wwwroot\nightclub_photography\data\images\30072013\0\62559_10151456622700100_611995567_n. jpg

    The file that is running the code to map the path is saved here:
    C:\inetpub\wwwroot\nightclub_photography\pages\add_sales.asp

    MapPath doesn't seem to work, what is the best method to map the path!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,567
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    It depends on your IIS settings.

    *IF* IIS is set to "allow parent paths", then from that ASP page you could use
    Code:
    imagePath = Server.MapPath("../data/images/30072013/0/") & RS("imagename")
    But if your server is not allowing parent paths, then you can't use ".." in Server.MapPath.

    But there's no reason you couldn't build your own:
    Code:
    currentDir = Server.MapPath(".") ' this should always be allowed
    ' if that path ends in a \ strip it off
    If Right(currentDir,1) = "\" Then currentDir = Left(currentDir,Len(currentDir)-1)
    ' then strip off everything after last remaining \
    upOne = Left( currentDir, InStrReverse(currentDir,"\") ) 
    ' and now you can build on that to get the full path:
    imagePath = upOne & "data\images\30072013\0\" & RS("imagename")
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-30-2013)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    This part /data/images/30072013/0/ can't be defined at the time though, it needs to be "guessed" as only the jpg name is saved in the database.

    In other words I need to save the jpg as
    /data/images/30072013/0/62559_10151456622700100_611995567_n.jpg
    in the database?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,567
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    How can I know the right answer to that? It's your application.

    I can't think of any reason I'd ever have a file path looking like that, but it's your code, your system.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    /data/images/30072013/0/62559_10151456622700100_611995567_n.jpg

    data = where all data to do with uploads goes
    images = all uploaded images
    30072013 = the session date (last 1 working night) - use the date like this so it's always unique
    0 = the upload set, when more images are uploaded that will be 1.

    You understand why the path is like that now?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,567
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    Then, yes, I would say you do need to store that full path in your DB. Unless you have that in other fields in the record associated with each image.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    martynball (07-31-2013)


  •  

    Posting Permissions

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