iscode
asked on
Multiple Image Delete And Remove Options [ URGENT ] Need help!!
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
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
ASKER
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
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
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_fie ldsStr,MM_ columnsStr )
MM_fieldsStr = FixFieldsForUpload(MM_fiel dsStr,MM_c olumnsStr)
end if
>>>With this
'if UploadFormRequest("delete_ image") = "" then
MM_columnsStr = FixColumnsForUpload(MM_fie ldsStr,MM_ columnsStr )
MM_fieldsStr = FixFieldsForUpload(MM_fiel dsStr,MM_c olumnsStr)
'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("d elete_imag e"),",")
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 _columnsSt r)-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.Fi leSystemOb ject")
ImagePath = Server.MapPath("..\site_im ages\")
for im = 1 to 3
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i mage"&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("d elete_imag e"),",")
'create file scripting object
Set File = CreateObject("Scripting.Fi leSystemOb ject")
ImagePath = Server.MapPath("..\site_im ages\")
'for im = 1 to 3
for im = LBound(Images2delete) to UBound(Images2delete)
ImageFile = ImagePath & "\" & (rs_about.Fields.Item(Imag es2delete( 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/inc PureUpload .asp" -->
<!--#include file="../Connections/confi g.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 .TotalByte s)
Set UploadRequest = CreateObject("Scripting.Di ctionary")
BuildUploadRequest RequestBin, """../site_images""", "file", "", "uniq"
If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("M M_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_redir ectPage)
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.ServerVariabl es("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("M M_update") ) <> "" And CStr(UploadFormRequest("MM _recordId" )) <> "") Then
MM_editConnection = MM_conngcocmembers_STRING
MM_editTable = "About"
MM_editColumn = "P_ID"
MM_recordId = "" + UploadFormRequest("MM_reco rdId") + ""
MM_editRedirectUrl = "default.asp"
MM_fieldsStr = "P_Image1|value|P_Image2|v alue|P_Ima ge3|value| P_Heading1 |value|P_P aragraph1| value|P_He ading2|val ue|P_Parag raph2|valu e|P_Paragr aph3|value "
MM_columnsStr = "P_Image1|',none,''|P_Imag e2|',none, ''|P_Image 3|',none,' '|P_Headin g1|',none, ''|P_Parag raph1|',no ne,''|P_He ading2|',n one,''|P_P aragraph2| ',none,''| P_Paragrap h3|',none, ''"
' create the MM_fields and MM_columns arrays
' toggle skip empty fields feature off
'if UploadFormRequest("delete_ image") = "" then
MM_columnsStr = FixColumnsForUpload(MM_fie ldsStr,MM_ columnsStr )
MM_fieldsStr = FixFieldsForUpload(MM_fiel dsStr,MM_c olumnsStr)
'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("d elete_imag e"),",")
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 _columnsSt r)-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("M M_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.ActiveConnectio n = 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("d elete_imag e"),",")
'create file scripting object
Set File = CreateObject("Scripting.Fi leSystemOb ject")
ImagePath = Server.MapPath("..\site_im ages\")
'for im = 1 to 3
for im = LBound(Images2delete) to UBound(Images2delete)
ImageFile = ImagePath & "\" & (rs_about.Fields.Item(Imag es2delete( 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_Image 1") <> "" Then
'create file scripting object
Set File = CreateObject("Scripting.Fi leSystemOb ject")
ImagePath = Server.MapPath("..\site_im ages\")
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i mage1").Va lue)
' check if file exists and if true delete the file
If fileExists(ImageFile) Then
File.DeleteFile(ImageFile)
End If
end if
if UploadFormRequest("P_Image 2") <> "" Then
'create file scripting object
Set File = CreateObject("Scripting.Fi leSystemOb ject")
ImagePath = Server.MapPath("..\site_im ages\")
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i mage2").Va lue)
' check if file exists and if true delete the file
If fileExists(ImageFile) Then
File.DeleteFile(ImageFile)
End If
end if
if UploadFormRequest("P_Image 3") <> "" Then
'create file scripting object
Set File = CreateObject("Scripting.Fi leSystemOb ject")
ImagePath = Server.MapPath("..\site_im ages\")
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i mage3").Va lue)
' 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.ActiveConnectio n.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR edirectUrl )
End If
End If
End If
%>
<html>
<head>
<script language="JavaScript">
<!--
function checkFileUpload(form,exten sions,requ ireUpload, sizeLimit, minWidth,m inHeight,m axWidth,ma xHeight,sa veWidth,sa veHeight) { //v2.0
document.MM_returnValue = true;
if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi," |").replac e(/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_re turnValue = 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,m axHeight,s aveWidth,s aveHeight) ;
} } }
}
function showImageDimensions(fieldI mg) { //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 .saveHeigh t].value = img.height;
document.MM_returnValue = true;
}
function checkImageDimensions(field ,sizeL,min W,minH,max W,maxH,sav eW,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-da ta" onSubmit="checkFileUpload( this,'GIF, JPG,JPEG,B MP,PNG',fa lse,'','', '','','',' ','');retu rn document.MM_returnValue">
<table border="0" cellpadding="2" width="100%">
<tr valign="top">
<td colspan="2">
<h1><%=(rs_about.Fields.It em("P_Head ing1").Val ue)%></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">Require d 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,J PEG,BMP,PN G',false,' ','','','' ,'','','') ">
</td>
</tr>
<%
If (rs_about.Fields.Item("P_I mage1").Va lue) <> "" Then
Response.Write("<tr><td class=""specialbold"">Exis ting Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_I mage1").Va lue)&"'></ td></tr>")
Else
Response.Write("") End if
%>
<tr>
<%
If (rs_about.Fields.Item("P_I mage1").Va lue) <> "" 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_H eading1"). Value)%>" size="30" maxlength="100">
</td>
</tr>
<tr>
<td class="specialbold">Paragr aph One*</td>
<td>
<textarea rows="6" name="P_Paragraph1" cols="40"><%=(rs_about.Fie lds.Item(" P_Paragrap h1").Value )%></texta rea>
</td>
</tr>
<tr>
<td class="specialbold">Page Sub Heading</td>
<td>
<input type="text" name="P_Heading2" value="<%=(rs_about.Fields .Item("P_H eading2"). 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,J PEG,BMP,PN G',false,' ','','','' ,'','','') ">
</td>
<%
If (rs_about.Fields.Item("P_I mage2").Va lue) <> "" Then
Response.Write("<tr><td class=""specialbold"">Exis ting Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_I mage2").Va lue)&"'></ td></tr>")
Else
Response.Write("") End if
%>
</tr>
<tr>
<%
If (rs_about.Fields.Item("P_I mage2").Va lue) <> "" 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">Paragr aph Two</td>
<td>
<textarea rows="6" name="P_Paragraph2" cols="40"><%=(rs_about.Fie lds.Item(" P_Paragrap h2").Value )%></texta rea>
</td>
</tr>
<tr>
<td class="specialbold">Image Three</td>
<td>
<input type="file" name="P_Image3" size="30" onChange="checkFileUpload( this.form, 'GIF,JPG,J PEG,BMP,PN G',false,' ','','','' ,'','','') ">
</td>
<%
If (rs_about.Fields.Item("P_I mage3").Va lue) <> "" Then
Response.Write("<tr><td class=""specialbold"">Exis ting Image</td><td> <img src='"&("../site_images/") & (rs_about.Fields.Item("P_I mage3").Va lue)&"'></ td></tr>")
Else
Response.Write("") End if
%>
</tr>
<tr>
<%
If (rs_about.Fields.Item("P_I mage3").Va lue) <> "" 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">Paragr aph Three</td>
<td>
<textarea rows="6" name="P_Paragraph3" cols="40"><%=(rs_about.Fie lds.Item(" P_Paragrap h3").Value )%></texta rea>
</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 <p> to start a new paragraph, <br> to
end a line, <br><br> to make a line space, and <a
href="linkpath"& gt;Link Text</a> 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
%>
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_
MM_columnsStr = FixColumnsForUpload(MM_fie
MM_fieldsStr = FixFieldsForUpload(MM_fiel
end if
>>>With this
'if UploadFormRequest("delete_
MM_columnsStr = FixColumnsForUpload(MM_fie
MM_fieldsStr = FixFieldsForUpload(MM_fiel
'end if
'===additional code
if UploadFormRequest("delete_
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("d
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_
MM_columnsStr = Mid(MM_columnsStr,1,Len(MM
end if
'===end of additional code
>>>>As well as this lines...
if UploadFormRequest("delete_
'create file scripting object
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("..\site_im
for im = 1 to 3
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i
' 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_
'Same concept as above....
Images2delete = Split(UploadFormRequest("d
'create file scripting object
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("..\site_im
'for im = 1 to 3
for im = LBound(Images2delete) to UBound(Images2delete)
ImageFile = ImagePath & "\" & (rs_about.Fields.Item(Imag
' 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/inc
<!--#include file="../Connections/confi
<!--#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_redirectPage = ""
Server.ScriptTimeout = 600
RequestBin = Request.BinaryRead(Request
Set UploadRequest = CreateObject("Scripting.Di
BuildUploadRequest RequestBin, """../site_images""", "file", "", "uniq"
If (GP_redirectPage <> "" and not (CStr(UploadFormRequest("M
If (InStr(1, GP_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
GP_redirectPage = GP_redirectPage & "?" & UploadQueryString
End If
Response.Redirect(GP_redir
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
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.ServerVariabl
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("M
MM_editConnection = MM_conngcocmembers_STRING
MM_editTable = "About"
MM_editColumn = "P_ID"
MM_recordId = "" + UploadFormRequest("MM_reco
MM_editRedirectUrl = "default.asp"
MM_fieldsStr = "P_Image1|value|P_Image2|v
MM_columnsStr = "P_Image1|',none,''|P_Imag
' create the MM_fields and MM_columns arrays
' toggle skip empty fields feature off
'if UploadFormRequest("delete_
MM_columnsStr = FixColumnsForUpload(MM_fie
MM_fieldsStr = FixFieldsForUpload(MM_fiel
'end if
'===additional code
if UploadFormRequest("delete_
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("d
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_
MM_columnsStr = Mid(MM_columnsStr,1,Len(MM
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_
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("M
' 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
MM_editCmd.ActiveConnectio
' delete the file before we delete the record
' check to see if user deleted all images
if UploadFormRequest("delete_
'Same concept as above....
Images2delete = Split(UploadFormRequest("d
'create file scripting object
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("..\site_im
'for im = 1 to 3
for im = LBound(Images2delete) to UBound(Images2delete)
ImageFile = ImagePath & "\" & (rs_about.Fields.Item(Imag
' 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_Image
'create file scripting object
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("..\site_im
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i
' check if file exists and if true delete the file
If fileExists(ImageFile) Then
File.DeleteFile(ImageFile)
End If
end if
if UploadFormRequest("P_Image
'create file scripting object
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("..\site_im
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i
' check if file exists and if true delete the file
If fileExists(ImageFile) Then
File.DeleteFile(ImageFile)
End If
end if
if UploadFormRequest("P_Image
'create file scripting object
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("..\site_im
ImageFile = ImagePath & "\" & (rs_about.Fields.Item("P_i
' 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.ActiveConnectio
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR
End If
End If
End If
%>
<html>
<head>
<script language="JavaScript">
<!--
function checkFileUpload(form,exten
document.MM_returnValue = true;
if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"
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_re
} 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|
if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
checkImageDimensions(field
} } }
}
function showImageDimensions(fieldI
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
if (img.saveHeight != '') document.PU_uploadForm[img
document.MM_returnValue = true;
}
function checkImageDimensions(field
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.
}
//-->
</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
</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%>
<table border="0" cellpadding="2" width="100%">
<tr valign="top">
<td colspan="2">
<h1><%=(rs_about.Fields.It
<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">Require
</tr>
<tr>
<td class="specialbold">Image One*</td>
<td>
<input type="file" name="P_Image1" size="30" onChange="checkFileUpload(
</td>
</tr>
<%
If (rs_about.Fields.Item("P_I
Response.Write("<tr><td class=""specialbold"">Exis
Else
Response.Write("") End if
%>
<tr>
<%
If (rs_about.Fields.Item("P_I
%>
<td class="specialbold">Remove
<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
</td>
</tr>
<tr>
<td class="specialbold">Paragr
<td>
<textarea rows="6" name="P_Paragraph1" cols="40"><%=(rs_about.Fie
</td>
</tr>
<tr>
<td class="specialbold">Page Sub Heading</td>
<td>
<input type="text" name="P_Heading2" value="<%=(rs_about.Fields
</td>
</tr>
<tr>
<td class="specialbold">Image Two</td>
<td>
<input type="file" name="P_Image2" size="30" onChange="checkFileUpload(
</td>
<%
If (rs_about.Fields.Item("P_I
Response.Write("<tr><td class=""specialbold"">Exis
Else
Response.Write("") End if
%>
</tr>
<tr>
<%
If (rs_about.Fields.Item("P_I
%>
<td class="specialbold">Remove
<span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
</tr> <tr>
<td class="specialbold">Paragr
<td>
<textarea rows="6" name="P_Paragraph2" cols="40"><%=(rs_about.Fie
</td>
</tr>
<tr>
<td class="specialbold">Image Three</td>
<td>
<input type="file" name="P_Image3" size="30" onChange="checkFileUpload(
</td>
<%
If (rs_about.Fields.Item("P_I
Response.Write("<tr><td class=""specialbold"">Exis
Else
Response.Write("") End if
%>
</tr>
<tr>
<%
If (rs_about.Fields.Item("P_I
%>
<td class="specialbold">Remove
<span class="tablesmall">check box to remove image</span></td>
<% Else
Response.Write("") End if
%>
</tr>
<tr>
<td class="specialbold">Paragr
<td>
<textarea rows="6" name="P_Paragraph3" cols="40"><%=(rs_about.Fie
</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 <p> to start a new paragraph, <br> to
end a line, <br><br> to make a line space, and <a
href="linkpath"&
</tr>
</table>
<input type="hidden" name="MM_update" value="true">
<input type="hidden" name="MM_recordId" value="<%= rs_about.Fields.Item("P_ID
</form>
</td>
</tr>
<tr>
<td colspan="2">
<!--#include file="bottom.asp"-->
</td>
</tr>
</table>
</body>
</html>
<% ' Semitco Close Connection
rs_about.ActiveConnection.
set rs_about.ActiveConnection = Nothing
set rs_about = Nothing
%>
ASKER
gladxml
There is one problem, you took out the remove all image checkbox, how do we
keep that included?
There is one problem, you took out the remove all image checkbox, how do we
keep that included?
ASKER
gladxml
and how about if I have image width and height in dadabase how do I remove that with selected image?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
gladxml
I made a new question at: https://www.experts-exchange.com/questions/21137374/follow-up-to-gladxml-remove-image-width-and-hight-from-db.html
for deleting image width and hight
I made a new question at: https://www.experts-exchange.com/questions/21137374/follow-up-to-gladxml-remove-image-width-and-hight-from-db.html
for deleting image width and hight
ASKER
gladxml
thank you for all your help
iscode,
Im glad to be of help.
Happy programming.
Im glad to be of help.
Happy programming.
Just change the connection object base as well as the db...
<%
Response.Buffer = true
dim cnn,rst
set cnn = Server.CreateObject("ADODB
cnn.Open "driver={Microsoft Access Driver (*.mdb)};;DBQ=" & Server.MapPath("Auction.md
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
https://www.experts-exchange.com/questions/20450556/request-form-with-a-local-variable.html
Happy programming...