Solved

Multiple Image Delete And Remove Options [ URGENT ] Need help!!

Posted on 2004-09-17
9
377 Views
Last Modified: 2008-02-01
I am working on a project in Asp with Dreamweaver MX to multiple delete images on server
directory and remove theyr related data in database from a form page with checkboxes.  
                  
I saw this tutorial on dmxzone.com called  "Multiple Image Delete & Remove Options for Pure ASP Upload" that is similar to what I am trying to do. So insted of filling this page with asp code
I thought its better to point out the link to the tutorial for detail and there is a zip file to download a demo.

The demo has "P_Image1"," P_Image2" and "P_Image3"  with upload button for each file
and 1 checkbox name "delete_image", if checked it will delete all 3 images on submit.

 In my project I have added checkbox under each image and named them
"delete_image1", "delete_image2" and "delete_image3" and am struggling to make it
work so I can delete the image I want to delete with checkbox for each insted of all images like in the demo.

 I have asked in dmxzone forum and emailed the author but get no reply's so I am hoping
you experts can help me out, if something is unclear please ask me.

Link To The Tutorial:
http://www.dmxzone.com/showDetail.asp?TypeId=2&NewsId=3214&LinkFile=multiple_image_deletes.htm

Download Tutorial Files:
http://www.dmxzone.com/Downloads/Tutorial_multiple_image_deletes_tutorial_1.zip/multiple_image_deletes_demo.zip


0
Comment
Question by:iscode
  • 5
  • 4
9 Comments
 
LVL 15

Expert Comment

by:gladxml
ID: 12091126
The below code will delete checkboxes that has been provided that the checkbox has the same name which is in the below is chkbox...

Just change the connection object base as well as the db...

<%
Response.Buffer = true
dim cnn,rst
set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open "driver={Microsoft Access Driver (*.mdb)};;DBQ=" & Server.MapPath("Auction.mdb")
if  request.form("Submit") = "Submit" then
    strsql = "DELETE FROM SaleItems WHERE SaleItemID = "
    For i = 1 to Request("chkbox").Count
         itemid = Request("chkbox")(i))
         cnn.execute strsql & itemid
    Next
end if
 %>

For related article kindly check out the link

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20450556.html

Happy programming...

0
 
LVL 6

Author Comment

by:iscode
ID: 12092651
gladxml

As I explained I am using Dreamweaver MX, I have  routine as you provided,
how would you  impliment this in the demo I am using?
this is its not helping me, you need show me where in the demo I add this
0
 
LVL 15

Expert Comment

by:gladxml
ID: 12095140
iscode,

Here the changes as what I have said on the my previous post... Actually the concept is the same but the problem here is that it uses the wizard of Dreamewaver which somewhat hard to understand since coding your own update statement would only consist of 5 to 6 lines... But anyway I try to use the concept on the exisiting code... it is also good enhnacement on your part... Below is a simple explanation of what I have done.

First you will notice that all checkbox have the same name which is "delete_image" and the value of the checkbox is the name of the textbox which is also the name of your fields in the database...

<input type="checkbox" name="delete_image" value="P_Image1">

Now on the server side code...

>>>I change this lines of code

if UploadFormRequest("delete_image") = "" then  
  MM_columnsStr = FixColumnsForUpload(MM_fieldsStr,MM_columnsStr)
  MM_fieldsStr = FixFieldsForUpload(MM_fieldsStr,MM_columnsStr)
end if

>>>With this

'if UploadFormRequest("delete_image") = "" then  
  MM_columnsStr = FixColumnsForUpload(MM_fieldsStr,MM_columnsStr)
  MM_fieldsStr = FixFieldsForUpload(MM_fieldsStr,MM_columnsStr)
'end if

'===additional code
if UploadFormRequest("delete_image") <> "" then
MM_fieldsStr = MM_fieldsStr & "|"
MM_columnsStr = MM_columnsStr & "|"
' Since the checkbox name is common therefore we can create an array
' cause it is separetd by comma if more than one checkbox is checked
Images2delete = Split(UploadFormRequest("delete_image"),",")
for  x= Lbound(Images2delete) to UBound(Images2delete)
MM_fieldsStr = MM_fieldsStr & Images2delete(x) & "|value|"
MM_columnsStr = MM_columnsStr & Images2delete(x) & "|',none,''|"
next

MM_fieldsStr = Mid(MM_fieldsStr,1,Len(MM_fieldsStr)-1)
MM_columnsStr = Mid(MM_columnsStr,1,Len(MM_columnsStr)-1)

end if
'===end of additional code

>>>>As well as this lines...

  if UploadFormRequest("delete_image") <> "" Then
    'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                for im = 1 to 3
                  ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image"&im).Value)
                  ' check if file exists and if true delete the file
                  If fileExists(ImageFile) Then
                     File.DeleteFile(ImageFile)
                  End If
                next
  end if


>>>with this

  if UploadFormRequest("delete_image") <> "" Then
'Same concept as above....
Images2delete = Split(UploadFormRequest("delete_image"),",")
    'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                'for im = 1 to 3
                        for im = LBound(Images2delete) to UBound(Images2delete)
                  ImageFile = ImagePath & "\" & (rs_about.Fields.Item(Images2delete(im)).Value)
                  ' check if file exists and if true delete the file
                  If fileExists(ImageFile) Then
                     File.DeleteFile(ImageFile)
                  End If
                next
  end if

>>>Happy Programming<<<<


======Below is the working code and the improvement you want to achieve===
======just cut and paste the code below =====
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../ScriptLibrary/incPureUpload.asp" -->
<!--#include file="../Connections/config.asp" -->
<!--#include file="security.asp" -->
<!--#include file="functions.asp" -->
<%
'*** Pure ASP File Upload -----------------------------------------------------
' Copyright (c) 2001 George Petrov, www.UDzone.com
' Process the upload
' Version: 2.0.5
'------------------------------------------------------------------------------
'*** File Upload to: """../site_images""", Extensions: "GIF,JPG,JPEG,BMP,PNG", Form: form1, Redirect: "", "file", "", "uniq", "false", "", "" , "", "", "", "", "600", "", "", ""

Dim GP_redirectPage, RequestBin, UploadQueryString, GP_uploadAction, UploadRequest
PureUploadSetup

If (CStr(Request.QueryString("GP_upload")) <> "") Then
  GP_redirectPage = ""
  Server.ScriptTimeout = 600
 
  RequestBin = Request.BinaryRead(Request.TotalBytes)
  Set UploadRequest = CreateObject("Scripting.Dictionary")  
  BuildUploadRequest RequestBin, """../site_images""", "file", "", "uniq"
 
  If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("MM_insert")) <> "" or CStr(UploadFormRequest("MM_update")) <> "")) Then
    If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
      GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
    End If
    Response.Redirect(GP_redirectPage)  
  end if  
else
  if UploadQueryString <> "" then
    UploadQueryString = UploadQueryString & "&GP_upload=true"
  else  
    UploadQueryString = "GP_upload=true"
  end if  
end if
' End Pure Upload
'------------------------------------------------------------------------------
%>
<%
set rs_about = Server.CreateObject("ADODB.Recordset")
rs_about.ActiveConnection = MM_conngcocmembers_STRING
rs_about.Source = "SELECT * FROM About"
rs_about.CursorType = 0
rs_about.CursorLocation = 2
rs_about.LockType = 3
rs_about.Open()
rs_about_numRows = 0
%>
<%
'===============================================================================
'WWWeb Concepts ASP Development Solutions www.ebconcepts.com
'This application designed and written by written by James W. Threadgill
'wayne@ebconcepts.com
'Copyright 2001. All Rights Reserved.
'===============================================================================

' *** Edit Operations: (Modified for File Upload) declare variables

MM_editAction = CStr(Request.ServerVariables("URL")) 'MM_editAction = CStr(Request("URL"))
If (UploadQueryString <> "") Then
  MM_editAction = MM_editAction & "?" & UploadQueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: (Modified for File Upload) set variables

If (CStr(UploadFormRequest("MM_update")) <> "" And CStr(UploadFormRequest("MM_recordId")) <> "") Then

  MM_editConnection = MM_conngcocmembers_STRING
  MM_editTable = "About"
  MM_editColumn = "P_ID"
  MM_recordId = "" + UploadFormRequest("MM_recordId") + ""
  MM_editRedirectUrl = "default.asp"
  MM_fieldsStr  = "P_Image1|value|P_Image2|value|P_Image3|value|P_Heading1|value|P_Paragraph1|value|P_Heading2|value|P_Paragraph2|value|P_Paragraph3|value"
  MM_columnsStr = "P_Image1|',none,''|P_Image2|',none,''|P_Image3|',none,''|P_Heading1|',none,''|P_Paragraph1|',none,''|P_Heading2|',none,''|P_Paragraph2|',none,''|P_Paragraph3|',none,''"
  ' create the MM_fields and MM_columns arrays
 ' toggle skip empty fields feature off
 
'if UploadFormRequest("delete_image") = "" then  
  MM_columnsStr = FixColumnsForUpload(MM_fieldsStr,MM_columnsStr)
  MM_fieldsStr = FixFieldsForUpload(MM_fieldsStr,MM_columnsStr)
'end if

'===additional code
if UploadFormRequest("delete_image") <> "" then
MM_fieldsStr = MM_fieldsStr & "|"
MM_columnsStr = MM_columnsStr & "|"

' Since the checkbox name is common therefore we can create an array
' cause it is separetd by comma if more than one checkbox is checked
Images2delete = Split(UploadFormRequest("delete_image"),",")
for  x= Lbound(Images2delete) to UBound(Images2delete)
MM_fieldsStr = MM_fieldsStr & Images2delete(x) & "|value|"
MM_columnsStr = MM_columnsStr & Images2delete(x) & "|',none,''|"
next

MM_fieldsStr = Mid(MM_fieldsStr,1,Len(MM_fieldsStr)-1)
MM_columnsStr = Mid(MM_columnsStr,1,Len(MM_columnsStr)-1)

end if
'===end of additional code

  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(UploadFormRequest(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And UploadQueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & UploadQueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & UploadQueryString
    End If
  End If

End If
%>
<%
' *** Update Record: (Modified for File Upload) construct a sql update statement and execute it

If (CStr(UploadFormRequest("MM_update")) <> "" And CStr(UploadFormRequest("MM_recordId")) <> "") Then

  ' create the sql update statement
  MM_editQuery = "update " & MM_editTable & " set "
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_editQuery = MM_editQuery & ","
    End If
    MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal
  Next
  MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

  If (Not MM_abortEdit) Then
    ' execute the update
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
' delete the file before we delete the record
' check to see if user deleted all images
  if UploadFormRequest("delete_image") <> "" Then
'Same concept as above....
Images2delete = Split(UploadFormRequest("delete_image"),",")
    'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                'for im = 1 to 3
                        for im = LBound(Images2delete) to UBound(Images2delete)
                  ImageFile = ImagePath & "\" & (rs_about.Fields.Item(Images2delete(im)).Value)
                  ' check if file exists and if true delete the file
                  If fileExists(ImageFile) Then
                     File.DeleteFile(ImageFile)
                  End If
                next
  end if
' check to see if the user has replaced an image and delete old image
'  find our what image is replaced and delete old image  
        if UploadFormRequest("P_Image1") <> "" Then
    'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image1").Value)
                ' check if file exists and if true delete the file
                If fileExists(ImageFile) Then
                   File.DeleteFile(ImageFile)
                End If
      end if
      if UploadFormRequest("P_Image2") <> "" Then
       'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image2").Value)
                ' check if file exists and if true delete the file
                If fileExists(ImageFile) Then
                   File.DeleteFile(ImageFile)
                End If
      end if
      if UploadFormRequest("P_Image3") <> "" Then
        'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image3").Value)
                ' check if file exists and if true delete the file
                If fileExists(ImageFile) Then
                   File.DeleteFile(ImageFile)
                End If
  end if
'end delete image code

    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If
End If
%>
<html>
<head>
<script language="JavaScript">
<!--

function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.0
  document.MM_returnValue = true;
  if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|").replace(/s/gi,"") + ")$","i");
  for (var i = 0; i<form.elements.length; i++) {
    field = form.elements[i];
    if (field.type.toUpperCase() != 'FILE') continue;
    if (field.value == '') {
      if (requireUpload) {alert('File is required!');document.MM_returnValue = false;field.focus();break;}
    } else {
      if(extensions != '' && !re.test(field.value)) {
        alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
        document.MM_returnValue = false;field.focus();break;
      }
    document.PU_uploadForm = form;
    re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
    if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
      checkImageDimensions(field,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
    } } }
}

function showImageDimensions(fieldImg) { //v2.0
  var isNS6 = (!document.all && document.getElementById ? true : false);
  var img = (fieldImg && !isNS6 ? fieldImg : this);
  if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
    alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight); return;}
  if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
    alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight); return;}
  if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
    alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes'); return;}
  if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
  if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
  document.MM_returnValue = true;
}

function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) { //v2.0
  if (!document.layers) {
    var isNS6 = (!document.all && document.getElementById ? true : false);
    document.MM_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/');
    if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
               with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
           gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
       } else showImageDimensions(field.gp_img);}
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Site Administration</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
<table border="0" cellpadding="0" cellspacing="0" width="650" align="center">
  <tr>
    <td colspan="2">
      <!--#include file="top.asp"-->
    </td>
  </tr>
  <tr>
    <td colspan="2" class="specialbold">Master Site Administration</td>
  </tr>
  <tr>
    <td colspan="2"><img src="images/spacer.gif" width="100" height="10"></td>
  </tr>
  <tr>
    <td width="125" valign="top">
      <!--#include file="menu_left.asp"-->
    </td>
    <td valign="top">
      <form name="form1" method="post" action="<%=MM_editAction%>" enctype="multipart/form-data" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','');return document.MM_returnValue">
        <table border="0" cellpadding="2" width="100%">
          <tr valign="top">
            <td colspan="2">
              <h1><%=(rs_about.Fields.Item("P_Heading1").Value)%></h1>
              <p>To update your About page content, change the contents of the
                text boxes below. Click submit to complete the update.</p>
            </td>
          </tr>
          <tr valign="top">
            <td colspan="2" class="tablesmall">Required fileds marked with *.</td>
          </tr>
          <tr>
            <td class="specialbold">Image One*</td>
            <td>
              <input type="file" name="P_Image1" size="30" onChange="checkFileUpload(this.form,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','')">
            </td>
          </tr>
<%
If (rs_about.Fields.Item("P_Image1").Value) <> "" Then
Response.Write("<tr><td class=""specialbold"">Existing Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_Image1").Value)&"'></td></tr>")
Else
Response.Write("") End if
 %>
<tr>      
<%
If  (rs_about.Fields.Item("P_Image1").Value) <> "" Then
%>
<td class="specialbold">Remove Images<br></td><td><input type="checkbox" name="delete_image" value="P_Image1">
              <span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
          </tr>          <tr>
            <td class="specialbold">Page Heading*</td>
            <td>
              <input type="text" name="P_Heading1" value="<%=(rs_about.Fields.Item("P_Heading1").Value)%>"  size="30" maxlength="100">
            </td>
          </tr>
          <tr>
            <td class="specialbold">Paragraph One*</td>
            <td>
              <textarea rows="6" name="P_Paragraph1" cols="40"><%=(rs_about.Fields.Item("P_Paragraph1").Value)%></textarea>
            </td>
          </tr>
          <tr>
            <td class="specialbold">Page Sub Heading</td>
            <td>
              <input type="text" name="P_Heading2" value="<%=(rs_about.Fields.Item("P_Heading2").Value)%>"  size="30">
            </td>
          </tr>
          <tr>
            <td class="specialbold">Image Two</td>
            <td>
              <input type="file" name="P_Image2" size="30" onChange="checkFileUpload(this.form,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','')">
            </td>
<%
If (rs_about.Fields.Item("P_Image2").Value) <> "" Then
Response.Write("<tr><td class=""specialbold"">Existing Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_Image2").Value)&"'></td></tr>")
Else
Response.Write("") End if
 %>
          </tr>
<tr>      
<%
If (rs_about.Fields.Item("P_Image2").Value) <> "" Then
%>
<td class="specialbold">Remove Images<br></td><td><input type="checkbox" name="delete_image" value="P_Image2">
              <span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
          </tr>           <tr>
            <td class="specialbold">Paragraph Two</td>
            <td>
              <textarea rows="6" name="P_Paragraph2" cols="40"><%=(rs_about.Fields.Item("P_Paragraph2").Value)%></textarea>
            </td>
          </tr>
          <tr>
            <td class="specialbold">Image Three</td>
            <td>
              <input type="file" name="P_Image3" size="30" onChange="checkFileUpload(this.form,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','')">
            </td>
            <%
If (rs_about.Fields.Item("P_Image3").Value) <> "" Then
Response.Write("<tr><td class=""specialbold"">Existing Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_Image3").Value)&"'></td></tr>")
Else
Response.Write("") End if
 %>
          </tr>
<tr>      
<%
If (rs_about.Fields.Item("P_Image3").Value) <> "" Then
%>
<td class="specialbold">Remove Images<br></td><td><input type="checkbox" name="delete_image" value="P_Image3">
              <span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
          </tr>
          <tr>
            <td class="specialbold">Paragraph Three</td>
            <td>
              <textarea rows="6" name="P_Paragraph3" cols="40"><%=(rs_about.Fields.Item("P_Paragraph3").Value)%></textarea>
            </td>
          </tr>
          <tr>
            <td class="specialbold"></td>
            <td><img src="images/spacer.gif" alt="" width="1" height="1"></td>
          </tr>
          <tr>
            <td class="specialbold"> </td>
            <td>
              <input type="submit" class="button" value="Update" name="Submit">
            </td>
          </tr>
          <tr>
            <td class="tablesmall" colspan="2"><i>HTML code can be input into
              this form: use &lt;p&gt; to start a new paragraph, &lt;br&gt; to
              end a line, &lt;br&gt;&lt;br&gt; to make a line space, and &lt;a
              href=&quot;linkpath&quot;&gt;Link Text&lt;/a&gt; for a hyperlink.</i></td>
          </tr>
        </table>
        <input type="hidden" name="MM_update" value="true">
        <input type="hidden" name="MM_recordId" value="<%= rs_about.Fields.Item("P_ID").Value %>">
      </form>
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <!--#include file="bottom.asp"-->
    </td>
  </tr>
</table>
</body>
</html>
<% ' Semitco Close Connection
rs_about.ActiveConnection.Close()
set rs_about.ActiveConnection = Nothing
set rs_about = Nothing
%>
0
 
LVL 6

Author Comment

by:iscode
ID: 12096079
gladxml

There is one problem, you took out the remove all image checkbox, how do we
keep that included?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 6

Author Comment

by:iscode
ID: 12097029

gladxml

and how about if I have image width and height in dadabase how do I remove that with selected image?
0
 
LVL 15

Accepted Solution

by:
gladxml earned 500 total points
ID: 12100401
iscode,

Below is the code... I added some client side code... so that we can have the same functionality that I had taken out on the original code... Just check the difference with the last code that I had posted... I use client side to control all the checkbox so that I will not modify the server side code again.

For this question

<<<and how about if I have image width and height in dadabase how do I remove that with selected image?>>>

if you already have the working code as what you have mention above please post it and it would be better to post it as a new question...

Hope this help...

Happy programming...

==just cut and paste the code below....

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../ScriptLibrary/incPureUpload.asp" -->
<!--#include file="../Connections/config.asp" -->
<!--#include file="security.asp" -->
<!--#include file="functions.asp" -->
<%
'*** Pure ASP File Upload -----------------------------------------------------
' Copyright (c) 2001 George Petrov, www.UDzone.com
' Process the upload
' Version: 2.0.5
'------------------------------------------------------------------------------
'*** File Upload to: """../site_images""", Extensions: "GIF,JPG,JPEG,BMP,PNG", Form: form1, Redirect: "", "file", "", "uniq", "false", "", "" , "", "", "", "", "600", "", "", ""

Dim GP_redirectPage, RequestBin, UploadQueryString, GP_uploadAction, UploadRequest
PureUploadSetup

If (CStr(Request.QueryString("GP_upload")) <> "") Then
  GP_redirectPage = ""
  Server.ScriptTimeout = 600
 
  RequestBin = Request.BinaryRead(Request.TotalBytes)
  Set UploadRequest = CreateObject("Scripting.Dictionary")  
  BuildUploadRequest RequestBin, """../site_images""", "file", "", "uniq"
 
  If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("MM_insert")) <> "" or CStr(UploadFormRequest("MM_update")) <> "")) Then
    If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
      GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
    End If
    Response.Redirect(GP_redirectPage)  
  end if  
else
  if UploadQueryString <> "" then
    UploadQueryString = UploadQueryString & "&GP_upload=true"
  else  
    UploadQueryString = "GP_upload=true"
  end if  
end if
' End Pure Upload
'------------------------------------------------------------------------------
%>
<%
set rs_about = Server.CreateObject("ADODB.Recordset")
rs_about.ActiveConnection = MM_conngcocmembers_STRING
rs_about.Source = "SELECT * FROM About"
rs_about.CursorType = 0
rs_about.CursorLocation = 2
rs_about.LockType = 3
rs_about.Open()
rs_about_numRows = 0
%>
<%
'===============================================================================
'WWWeb Concepts ASP Development Solutions www.ebconcepts.com
'This application designed and written by written by James W. Threadgill
'wayne@ebconcepts.com
'Copyright 2001. All Rights Reserved.
'===============================================================================

' *** Edit Operations: (Modified for File Upload) declare variables

MM_editAction = CStr(Request.ServerVariables("URL")) 'MM_editAction = CStr(Request("URL"))
If (UploadQueryString <> "") Then
  MM_editAction = MM_editAction & "?" & UploadQueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: (Modified for File Upload) set variables

If (CStr(UploadFormRequest("MM_update")) <> "" And CStr(UploadFormRequest("MM_recordId")) <> "") Then

  MM_editConnection = MM_conngcocmembers_STRING
  MM_editTable = "About"
  MM_editColumn = "P_ID"
  MM_recordId = "" + UploadFormRequest("MM_recordId") + ""
  MM_editRedirectUrl = "default.asp"
  MM_fieldsStr  = "P_Image1|value|P_Image2|value|P_Image3|value|P_Heading1|value|P_Paragraph1|value|P_Heading2|value|P_Paragraph2|value|P_Paragraph3|value"
  MM_columnsStr = "P_Image1|',none,''|P_Image2|',none,''|P_Image3|',none,''|P_Heading1|',none,''|P_Paragraph1|',none,''|P_Heading2|',none,''|P_Paragraph2|',none,''|P_Paragraph3|',none,''"
  ' create the MM_fields and MM_columns arrays
 ' toggle skip empty fields feature off
 
'if UploadFormRequest("delete_image") = "" then  
  MM_columnsStr = FixColumnsForUpload(MM_fieldsStr,MM_columnsStr)
  MM_fieldsStr = FixFieldsForUpload(MM_fieldsStr,MM_columnsStr)
'end if

'===additional code
if UploadFormRequest("delete_image") <> "" then
MM_fieldsStr = MM_fieldsStr & "|"
MM_columnsStr = MM_columnsStr & "|"

' Since the checkbox name is common therefore we can create an array
' cause it is separetd by comma if more than one checkbox is checked
Images2delete = Split(UploadFormRequest("delete_image"),",")
for  x= Lbound(Images2delete) to UBound(Images2delete)
MM_fieldsStr = MM_fieldsStr & Images2delete(x) & "|value|"
MM_columnsStr = MM_columnsStr & Images2delete(x) & "|',none,''|"
next

MM_fieldsStr = Mid(MM_fieldsStr,1,Len(MM_fieldsStr)-1)
MM_columnsStr = Mid(MM_columnsStr,1,Len(MM_columnsStr)-1)

end if
'===end of additional code

  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(i+1) = CStr(UploadFormRequest(MM_fields(i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And UploadQueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & UploadQueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & UploadQueryString
    End If
  End If

End If
%>
<%
' *** Update Record: (Modified for File Upload) construct a sql update statement and execute it

If (CStr(UploadFormRequest("MM_update")) <> "" And CStr(UploadFormRequest("MM_recordId")) <> "") Then

  ' create the sql update statement
  MM_editQuery = "update " & MM_editTable & " set "
  For i = LBound(MM_fields) To UBound(MM_fields) Step 2
    FormVal = MM_fields(i+1)
    MM_typeArray = Split(MM_columns(i+1),",")
    Delim = MM_typeArray(0)
    If (Delim = "none") Then Delim = ""
    AltVal = MM_typeArray(1)
    If (AltVal = "none") Then AltVal = ""
    EmptyVal = MM_typeArray(2)
    If (EmptyVal = "none") Then EmptyVal = ""
    If (FormVal = "") Then
      FormVal = EmptyVal
    Else
      If (AltVal <> "") Then
        FormVal = AltVal
      ElseIf (Delim = "'") Then  ' escape quotes
        FormVal = "'" & Replace(FormVal,"'","''") & "'"
      Else
        FormVal = Delim + FormVal + Delim
      End If
    End If
    If (i <> LBound(MM_fields)) Then
      MM_editQuery = MM_editQuery & ","
    End If
    MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal
  Next
  MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

  If (Not MM_abortEdit) Then
    ' execute the update
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
' delete the file before we delete the record
' check to see if user deleted all images
  if UploadFormRequest("delete_image") <> "" Then
'Same concept as above....
Images2delete = Split(UploadFormRequest("delete_image"),",")
    'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                'for im = 1 to 3
                    for im = LBound(Images2delete) to UBound(Images2delete)
                  ImageFile = ImagePath & "\" & (rs_about.Fields.Item(Images2delete(im)).Value)
                  ' check if file exists and if true delete the file
                  If fileExists(ImageFile) Then
                     File.DeleteFile(ImageFile)
                  End If
                next
  end if
' check to see if the user has replaced an image and delete old image
'  find our what image is replaced and delete old image  
       if UploadFormRequest("P_Image1") <> "" Then
    'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image1").Value)
                ' check if file exists and if true delete the file
                If fileExists(ImageFile) Then
                   File.DeleteFile(ImageFile)
                End If
     end if
     if UploadFormRequest("P_Image2") <> "" Then
      'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image2").Value)
                ' check if file exists and if true delete the file
                If fileExists(ImageFile) Then
                   File.DeleteFile(ImageFile)
                End If
     end if
     if UploadFormRequest("P_Image3") <> "" Then
       'create file scripting object
                Set File = CreateObject("Scripting.FileSystemObject")
                ImagePath = Server.MapPath("..\site_images\")
                ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_image3").Value)
                ' check if file exists and if true delete the file
                If fileExists(ImageFile) Then
                   File.DeleteFile(ImageFile)
                End If
  end if
'end delete image code

    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If
End If
%>
<html>
<head>
<script language="JavaScript">
<!--

function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.0
  document.MM_returnValue = true;
  if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|").replace(/s/gi,"") + ")$","i");
  for (var i = 0; i<form.elements.length; i++) {
    field = form.elements[i];
    if (field.type.toUpperCase() != 'FILE') continue;
    if (field.value == '') {
      if (requireUpload) {alert('File is required!');document.MM_returnValue = false;field.focus();break;}
    } else {
      if(extensions != '' && !re.test(field.value)) {
        alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
        document.MM_returnValue = false;field.focus();break;
      }
    document.PU_uploadForm = form;
    re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
    if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
      checkImageDimensions(field,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
    } } }
}

function showImageDimensions(fieldImg) { //v2.0
  var isNS6 = (!document.all && document.getElementById ? true : false);
  var img = (fieldImg && !isNS6 ? fieldImg : this);
  if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
    alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight); return;}
  if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
    alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight); return;}
  if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
    alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes'); return;}
  if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
  if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
  document.MM_returnValue = true;
}

function checkImageDimensions(field,sizeL,minW,minH,maxW,maxH,saveW,saveH) { //v2.0
  if (!document.layers) {
    var isNS6 = (!document.all && document.getElementById ? true : false);
    document.MM_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/');
    if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
             with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
          gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
      } else showImageDimensions(field.gp_img);}
}
//additional client side code

function CheckAll(fr)
{

      for (var i=0;i<fr.elements.length;i++)
      {
            var e = fr.elements[i];
            if ((e.name != 'allbox') && (e.type=='checkbox'))
            e.checked = fr.allbox.checked;
      }
}
function CheckCheckAll(fr)
{
      var TotalBoxes = 0;
      var TotalOn = 0;
      for (var i=0;i<fr.elements.length;i++)
      {
            var e = fr.elements[i];
            if ((e.name != 'allbox') && (e.type=='checkbox'))
            {
                  TotalBoxes++;
            if (e.checked)
            {
                  TotalOn++;
            }
            }
      }
      if (TotalBoxes==TotalOn)
      {fr.allbox.checked=true;}
      else
      {fr.allbox.checked=false;}
}
//end additional client side code
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Site Administration</title>
<link rel="stylesheet" type="text/css" href="../style.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" leftmargin="0">
<table border="0" cellpadding="0" cellspacing="0" width="650" align="center">
  <tr>
    <td colspan="2">
      <!--#include file="top.asp"-->
    </td>
  </tr>
  <tr>
    <td colspan="2" class="specialbold">Master Site Administration</td>
  </tr>
  <tr>
    <td colspan="2"><img src="images/spacer.gif" width="100" height="10"></td>
  </tr>
  <tr>
    <td width="125" valign="top">
      <!--#include file="menu_left.asp"-->
    </td>
    <td valign="top">
      <form name="form1" method="post" action="<%=MM_editAction%>" enctype="multipart/form-data" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','');return document.MM_returnValue">
        <table border="0" cellpadding="2" width="100%">
          <tr valign="top">
            <td colspan="2">
              <h1><%=(rs_about.Fields.Item("P_Heading1").Value)%></h1>
              <p>To update your About page content, change the contents of the
                text boxes below. Click submit to complete the update.</p>
            </td>
          </tr>
          <tr valign="top">
            <td colspan="2" class="tablesmall">Required fileds marked with *.</td>
          </tr>
          <tr>
            <td class="specialbold">Image One*</td>
            <td>
              <input type="file" name="P_Image1" size="30" onChange="checkFileUpload(this.form,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','')">
            </td>
          </tr>
<%
If (rs_about.Fields.Item("P_Image1").Value) <> "" Then
Response.Write("<tr><td class=""specialbold"">Existing Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_Image1").Value)&"'></td></tr>")
Else
Response.Write("") End if
 %>
<tr>      
<%
If  (rs_about.Fields.Item("P_Image1").Value) <> "" Then
%>
            <td class="specialbold">Remove Image<br></td><td><input type="checkbox" name="delete_image" value="P_Image1"  onClick="CheckCheckAll(this.form);">
              <span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
          </tr>          <tr>
            <td class="specialbold">Page Heading*</td>
            <td>
              <input type="text" name="P_Heading1" value="<%=(rs_about.Fields.Item("P_Heading1").Value)%>"  size="30" maxlength="100">
            </td>
          </tr>
          <tr>
            <td class="specialbold">Paragraph One*</td>
            <td>
              <textarea rows="6" name="P_Paragraph1" cols="40"><%=(rs_about.Fields.Item("P_Paragraph1").Value)%></textarea>
            </td>
          </tr>
          <tr>
            <td class="specialbold">Page Sub Heading</td>
            <td>
              <input type="text" name="P_Heading2" value="<%=(rs_about.Fields.Item("P_Heading2").Value)%>"  size="30">
            </td>
          </tr>
          <tr>
            <td class="specialbold">Image Two</td>
            <td>
              <input type="file" name="P_Image2" size="30" onChange="checkFileUpload(this.form,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','')">
            </td>
<%
If (rs_about.Fields.Item("P_Image2").Value) <> "" Then
Response.Write("<tr><td class=""specialbold"">Existing Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_Image2").Value)&"'></td></tr>")
Else
Response.Write("") End if
 %>
          </tr>
<tr>      
<%
If (rs_about.Fields.Item("P_Image2").Value) <> "" Then
%>
            <td class="specialbold">Remove Image<br></td><td><input type="checkbox" name="delete_image" value="P_Image2" onClick="CheckCheckAll(this.form);">
              <span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
          </tr>           <tr>
            <td class="specialbold">Paragraph Two</td>
            <td>
              <textarea rows="6" name="P_Paragraph2" cols="40"><%=(rs_about.Fields.Item("P_Paragraph2").Value)%></textarea>
            </td>
          </tr>
          <tr>
            <td class="specialbold">Image Three</td>
            <td>
              <input type="file" name="P_Image3" size="30" onChange="checkFileUpload(this.form,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','')">
            </td>
            <%
If (rs_about.Fields.Item("P_Image3").Value) <> "" Then
Response.Write("<tr><td class=""specialbold"">Existing Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_Image3").Value)&"'></td></tr>")
Else
Response.Write("") End if
 %>
          </tr>
<tr>      
<%
If (rs_about.Fields.Item("P_Image3").Value) <> "" Then
%>
            <td class="specialbold">Remove Image<br></td><td><input type="checkbox" name="delete_image" value="P_Image3"  onClick="CheckCheckAll(this.form);">
              <span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
          </tr>
          <tr>
            <td class="specialbold">Paragraph Three</td>
            <td>
              <textarea rows="6" name="P_Paragraph3" cols="40"><%=(rs_about.Fields.Item("P_Paragraph3").Value)%></textarea>
            </td>
          </tr>
<tr>      
<%
If (rs_about.Fields.Item("P_Image1").Value) <> "" OR (rs_about.Fields.Item("P_Image2").Value) <> "" OR (rs_about.Fields.Item("P_Image3").Value) <> "" Then
%>
            <td class="specialbold">Remove All Images<br></td><td>
                  <input type="checkbox" name="allbox" value="Check All" onClick="CheckAll(this.form);">
              <span class="tablesmall">check box to remove all images</span></td>
<% Else
Response.Write("") End if
%>
          </tr>          <tr>
            <td class="specialbold"></td>
            <td><img src="images/spacer.gif" alt="" width="1" height="1"></td>
          </tr>
          <tr>
            <td class="specialbold"> </td>
            <td>
              <input type="submit" class="button" value="Update" name="Submit">
            </td>
          </tr>
          <tr>
            <td class="tablesmall" colspan="2"><i>HTML code can be input into
              this form: use &lt;p&gt; to start a new paragraph, &lt;br&gt; to
              end a line, &lt;br&gt;&lt;br&gt; to make a line space, and &lt;a
              href=&quot;linkpath&quot;&gt;Link Text&lt;/a&gt; for a hyperlink.</i></td>
          </tr>
        </table>
        <input type="hidden" name="MM_update" value="true">
        <input type="hidden" name="MM_recordId" value="<%= rs_about.Fields.Item("P_ID").Value %>">
      </form>
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <!--#include file="bottom.asp"-->
    </td>
  </tr>
</table>
</body>
</html>
<% ' Semitco Close Connection
rs_about.ActiveConnection.Close()
set rs_about.ActiveConnection = Nothing
set rs_about = Nothing
%>
0
 
LVL 6

Author Comment

by:iscode
ID: 12100700
gladxml

I made a new question at:  http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21137374.html

for deleting  image width and hight
0
 
LVL 6

Author Comment

by:iscode
ID: 12115529

gladxml

thank you for all your help
0
 
LVL 15

Expert Comment

by:gladxml
ID: 12119475
iscode,

Im glad to be of help.

Happy programming.

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now