Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 17th, 2005, 08:27 AM
Authorized User
 
Join Date: Sep 2003
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to zaeem Send a message via Yahoo to zaeem
Default Deleting a Picture on The Server

Hello
I am building online address book sort of thing where members can upload their pictures.
Now when members update their member information along with the picture, the previous picture stays at the server. The picture path is something like” C:\Inetpub\wwwroot\address\pics\me1.jpg”, now tell me by using ASP how can I Delete the previous picture of the member at the server.

Millions of thanx in advance
Zaeem Sherazi


Zaeem Sherazi
__________________
Zaeem Sherazi
 
Old May 6th, 2005, 11:32 AM
Registered User
 
Join Date: May 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is what I use!
The code calls a folder on the server and basically displays everything in the directory... To test it, Name this code IMGVIEW.asp
Place it in a folder in the root called TEST
( C:/InetPub/wwwRoot/TEST)
Inside the "Test" folder on your root, create a folder called "IMAGES" (EG: C:\InetPub\wwwRoot\Test\Images )and put a few pictures in there... Open your browser, http://yourcomputername/Test/ImgView.asp
You don not need to change ANY of the code if you follow those instructions!
Good Luck!

<%@ Language=VBScript %>
<% Option Explicit %>
<%
Const ImageFilePath = "images"
Const DeleteButtonLabel = "Delete Selected Images"

Dim objFSO
Dim objFolder
Dim objFile
'10
Dim strFileName
Dim strFileExtension

Dim blnShowImages
'15
If Request.QueryString("ShowImages") = "" Then
    blnShowImages = True
Else
    blnShowImages = CBool(Request.QueryString("ShowImages"))
End If
'21
If Request.Form("btnDelete") = DeleteButtonLabel Then
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

    For Each strFileName In Request.Form("delete")
        objFSO.DeleteFile(Server.MapPath(ImageFilePath & "/" & strFileName))
    Next ' strFileName

    Set objFSO = Nothing
End If
%>
<html>
<head>
  <title>Image Browser</title>
</head>
<body>

<form action="<%= Request.ServerVariables("URL") %>" method="post">

<table border="1">
<tr><B>Please Note</B><BR> Once you choose to delete a selected item you cannot change it!<BR>Be careful with this... it doesn't ask "Are you sure?" and it doesn't offer any undelete capability so before you click on the button to delete selected items make sure those check marks are in the right places!
    <th>Image Name</th>
    <th>Image <a href="<%= Request.ServerVariables("URL") %>?ShowImages=<%= Not blnShowImages %>">(Toggle Display)</a></th>
    <th>Delete This Image</th>
</tr>
<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath("\images"))
'49
For Each objFile In objFolder.Files
    strFileExtension = LCase(Mid(objFile.Name, InStrRev(objFile.Name, ".", -1, 1) + 1))

    'If strFileExtension = "gif" Or strFileExtension = "jpg" Or strFileExtension = "jpeg" Then
    ' Original image file identification option:
    'If objFile.Type = "GIF Image" Or objFile.Type = "JPEG Image" Then
        %>
        <tr>
        <td>
            <a href="<%= ImageFilePath & "/" & objFile.Name %>"><%= objFile.Name %></a>
        </td>
        <%
        If blnShowImages Then
            %>
            <td>
                <img src="<%= ImageFilePath & "/" & objFile.Name %>" />
            </td>
            <%
        Else
            %>
            <td>
                <a href="<%= ImageFilePath & "/" & objFile.Name %>">View File</a>
            </td>
            <%
        End If
        %>
        <td align="center">
            <input type="checkbox" name="delete" value="<%= objFile.Name %>" />
        </td>
        <%
'80
    'End If
Next ' objFile

Set objFolder = Nothing
Set objFSO = Nothing
%>
<tr>
    <td colspan="3" align="right">
        <input type="submit" name="btnDelete" value="<%= DeleteButtonLabel %>">
    </td>
</tr>
</table>
</form>
</body>
</html>







Similar Threads
Thread Thread Starter Forum Replies Last Post
managing picture using oracle or sql server vedant Oracle 3 January 28th, 2008 08:59 PM
Store an picture in SQL Server ashoka_klt SQL Server 2000 1 October 29th, 2006 11:27 PM
How to insert a Picture in SQL Server using VB 6.0 swadhinm Pro VB Databases 0 September 21st, 2005 06:52 AM
Deleting a Picture on The Server zaeem Classic ASP Professional 1 September 8th, 2005 01:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.