This tutorial is the second of a three part series on image delete options using George Petrov's Pure ASP upload. The first shows how to handle image delete and remove options on an update form with a single image. This tutorial looks at update forms with multiple image fields. Having more than one image imposes limitations on image remove and delete options, but with a bit of imaginative thinking and a little hand coding we'll see that we can provide users with a full array of image handling options.
Multiple Image Delete & Remove Options for Pure ASP Upload
Look for UD code block below. <% Just below the UD comment in bold above is where we insert the code
to toggle skip empty fields feature on or off. The skip empty fields feature
default is on, so we're going to insert a bit of code that turns it off.
This way the null value from the image form fields will update the database
to a null value. All that's really needed is the first line beginning
with if and the last line that closes the if then statement "end
if." The other two lines are produced by PureASP
UpLoad 2.07. ' toggle skip empty fields
feature off In this section we check two conditions: The user is deleting the existing image or is uploading a new image. In either case, we delete the existing image. First we check if the database has a value for an existing image, then check if the image exists on the server, and if it exists, delete it. We use the two functions from Marcellino Bommezijn's great tutorial on deleting images when updating or deleting a record. Then we can follow his instructions and insert them here or they can used in include as well. (In the demo application you'll find the functions in functions.asp which is included in the update form page.) <% Notice we place the functions above the UD comment in bold that begins the UD code block below. <% Then we a insert version of the code from Marcellino Bommezijn's tutorial
that has been modified with a for each statement to loop through the image
fields. Be certain to note the last line of code above in bold black and
the first line of code below in bold black. The creation of the fso and
image delete must occur in this spacebefore the update query executes.
We check to see if user selected the checkbox we created to remove all
images. If either condition is true, we execute the delete. ' delete the file before
we delete the record If you don't use numbers to differ your image fields, then you must do
this. Remember what I said about considering your database design making
things simpler? ' delete the file before we delete
the record Now we've handled the option to delete all the images and set all the
database fields back to null values. But what if the user wants only to
update on or two of the images? In that case, we don't have to worry about
toggling the skip empty fields feature because we have a new image name
for the database field. But we still want to get that old image off the
server. So we're going to use little trickery to get our users to help
us out with that on the next page.
|
James Threadgill
James Threadgill has authored numerous tutorials on ASP and ASP.NET web development, published on such sites as the Dynamic Zones and MSDN Accademic Alliance. He co-authored the Sam's book Dreamweaver MX: ASP.NET Web Development.
James first began computer programming in 1995 while attending Alvin Community College. He completed a certificate of computer science program and an Associate of Arts degree at Alvin before going on to the University of Houston-Clear Lake where he was awarded a Bachelor of Science and a Master of Arts.
James publishes fiction, poetry, and visual arts under the name Wayne James. His fiction first appeared in Raconteur in 1995 and since has been published numerous times: in Hadrosaur Tales 5 and 7, Bayousphere, and in the Write Gallery e-zine. His poetry first appeared in the small press magazine Lucidity in 1996 and has been published numerous times since. His collection of fiction and poetry, When Only the Moon Rages, was released in 2000. Most recently his work appeared in Tales of the Talisman winter 2010 and spring 2011 issues. James currently attends graduate school at the University of Houston and owns and operates small web design and internet marketing firm, WWWeb Concepts, with his wife, Karen, in Houston, TX USA.
Comments
remove checkbox
How do I remove just 1 or 2 images?
How can I use checkbox to "delete_images1" , "delete_images2" and "delete_images3" with out deleting all images?
You must me logged in to write a comment.