Tech Off Thread

5 posts

Images not getting displayed in classic ASP

Back to Forum: Tech Off
  • User profile image
    venkatzeus

    Hi,

     

    I am using classic ASP. I have few images in my folder, which is inside the wwwroot of the server. I am trying to display the images in a ASP page. Below is the code i have used.

     

    <% Option Explicit %> 
    <html> <head> <title>Untitled</title> </head> 
    <body> 
    <form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post">
     <input type="text" name="directory" value="D:\NewFolder\"/> 
    <input type="submit"> 
    </form> 
    <% 
    Dim strPath, fso, fsoFolder, fsoFile, i 
    If Request.Form("directory") <> "" Then
     strPath = Request.Form("directory") 
    If Not Right(strPath, 1) = "\" Then 
    strPath = strPath & "\" 
    End If 
    Set fso = Server.CreateObject("Scripting.FileSystemObject") 
    If fso.FolderExists(strPath) = True Then 
    Set fsoFolder = fso.GetFolder(strPath) 
    i = 1 
    For Each fsoFile In fsoFolder.Files 
    If UCase(fso.GetExtensionName(fsoFile.Name)) = "JPG" Or 
    _ UCase(fso.GetExtensionName(fsoFile.Name)) = "GIF" Then 
    i = i + 1 
    Response.Write "<img src=""" & strPath & fsoFile.Name & """ height=""80"" border=""0"" alt=""" & fsoFile.Name & """>" 
     
    If i = 10 Then Response.Write "<br>" 
    End If 
    Next 
    Else 
    Response.Write("Folder " & strPath & " does not exist.") 
    End If 
    Set fso=nothing 
    Set fsoFolder=nothing 
    End If 
    %> 
    </body> </html>
    

     

    The images are existing in the computer itself. In the output, i am getting the broken image icon only.

     

    How to display the images in ASP?

     

    Thank you

  • User profile image
    W3bbo

    It seems to me as though you've neglected the first step of web-application debugging: looking at the generated HTML sent to the browser.

     

    If you do, you'll see that your script is sending absolute file paths to the client. You should be sending paths relative to the current script URL.

  • User profile image
    venkatzeus

    W3bbo said:

    It seems to me as though you've neglected the first step of web-application debugging: looking at the generated HTML sent to the browser.

     

    If you do, you'll see that your script is sending absolute file paths to the client. You should be sending paths relative to the current script URL.

    Hi,

     

    Thank you very much for the reply.

    The Images are available in the server's (D:\Newfolder) path.

     

    How to convert this absolute path to a relative path in ASP and send.

     

    Could you please help me in this.

     

    Thank you

     

  • User profile image
    ZippyV

    venkatzeus said:
    W3bbo said:
    *snip*

    Hi,

     

    Thank you very much for the reply.

    The Images are available in the server's (D:\Newfolder) path.

     

    How to convert this absolute path to a relative path in ASP and send.

     

    Could you please help me in this.

     

    Thank you

     

    That folder should be a subdirectory of your website, not a random directory on your server. IIS is not configured to serve files from that directory.

  • User profile image
    venkatzeus

    ZippyV said:
    venkatzeus said:
    *snip*

    That folder should be a subdirectory of your website, not a random directory on your server. IIS is not configured to serve files from that directory.

    Thank you very much for the reply.

     

    I got it.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.