George Petrov Pure ASP Upload - Old File Not Deleted When Updating Record
Posted on 2004-10-29
I've come across a problem where I'm unable to delete an image from my uploaded images folder when updating. The database record is being written just fine and the new image is put in place without a problem. I'm using George Petrov's PureASP Upload 2.09 extension for the upload script.
PureUpload - Using Full Path
Site on a virtual directory (read, write and scripts allowed)
Recordset is opened at the very top of the page
The images folder is 3 levels deep from root (i.e. root/admin/inventory/images)
Here is the delete code; the code in asterisks is the only code I've changed from the Dreamweaver auto generated and PureUpload generated:
' 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 MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
MM_formVal = MM_delim + MM_formVal + MM_delim
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
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
' This is where we delete the file before we delete the record!
Set File = CreateObject("Scripting.FileSystemObject")
ImagePath = Server.MapPath("\")
ImagePath = ImagePath & "\" & (Recordset1.Fields.Item("Photo").Value)
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
MM_editCmd.CommandText = MM_editQuery
If (MM_editRedirectUrl <> "") Then
I hope this makes some sense. I've used this script without a problem before, but it's not working on my home IIS even with full rights given to the IUSR account. Please let me know if you would like more information.