soporific
asked on
George Petrov Pure ASP Upload - Old File Not Deleted When Updating Record
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/image s)
Here is the delete code; the code in asterisks is the only code I've changed from the Dreamweaver auto generated and PureUpload generated:
****************
<%
Function newFileSystemObject()
set newFileSystemObject=Server .CreateObj ect("Scrip ting.FileS ystemObjec t")
End Function
%>
<%
Function fileExists(aFileSpec)
fileExists=newFileSystemOb ject.fileE xists(aFil eSpec)
End Function
%>
****************
<%
' 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 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
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","'' ") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_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
****************
' This is where we delete the file before we delete the record!
Set File = CreateObject("Scripting.Fi leSystemOb ject")
ImagePath = Server.MapPath("\")
ImagePath = ImagePath & "\" & (Recordset1.Fields.Item("P hoto").Val ue)
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If
***************
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
%>
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.
Thanks
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/image
Here is the delete code; the code in asterisks is the only code I've changed from the Dreamweaver auto generated and PureUpload generated:
****************
<%
Function newFileSystemObject()
set newFileSystemObject=Server
End Function
%>
<%
Function fileExists(aFileSpec)
fileExists=newFileSystemOb
End Function
%>
****************
<%
' 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 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
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_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
****************
' This is where we delete the file before we delete the record!
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("\")
ImagePath = ImagePath & "\" & (Recordset1.Fields.Item("P
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If
***************
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
%>
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.
Thanks
It sounds like permissions issue. Just for testing, in Windows Explorer, right click on the directory, go to security tab, and add Everyone. Then give full control to Everyone and try again.
ASKER
I set the images folder to Everyone (Full Control) and then also did the root folder, still no deletions, and no errors either. Is there some way I can view a log to see what it's processing?
Thanks for the reply,
~S
Thanks for the reply,
~S
Try outputing your path to make sure it is mapped correctly. Insert
Response.write(ImagePath)
before checking if file exists. It's very likely that delete statment is never executed because the file is not found by FileExists.
Response.write(ImagePath)
before checking if file exists. It's very likely that delete statment is never executed because the file is not found by FileExists.
ASKER
Sorry, I haven't used Response.write in a page yet. I'm not sure where to find that output; it's not showing up on the page. Also I'm getting ID=1& at the of the URL when it forwards to the succeed page, which I don't remember ever happening to any of my other pages before (if that makes a difference).
~S
~S
Here is your excerpt along with Response.write. Just drop it in your code and you will see output when you navigate to your page:
****************
' This is where we delete the file before we delete the record!
Set File = CreateObject("Scripting.Fi leSystemOb ject")
ImagePath = Server.MapPath("\")
ImagePath = ImagePath & "\" & (Recordset1.Fields.Item("P hoto").Val ue)
Response.write(ImagePath)
Response.end
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If
***************
****************
' This is where we delete the file before we delete the record!
Set File = CreateObject("Scripting.Fi
ImagePath = Server.MapPath("\")
ImagePath = ImagePath & "\" & (Recordset1.Fields.Item("P
Response.write(ImagePath)
Response.end
' check if file exists and if true delete the file
If fileExists(ImagePath) Then
File.DeleteFile(ImagePath)
End If
***************
ASKER
Ok, I'll try it in just a couple minutes. I didn't have reponse end, but that's exactly where I put Reponse.Write.
Thanks,
~S
Thanks,
~S
ASKER
Now I see what's happening:
c:\inetpub\wwwroot\/Lodgin g/admin/in ventory/im ages/count ry_inn_tin y.g
I have my virtual directory on my D drive, basically I told IIS to make a virtual directory named Lodging on the D drive and it seems to me that it's trying to edit off C instead of D. Is this the case, or should it be okay anyways?
c:\inetpub\wwwroot\/Lodgin
I have my virtual directory on my D drive, basically I told IIS to make a virtual directory named Lodging on the D drive and it seems to me that it's trying to edit off C instead of D. Is this the case, or should it be okay anyways?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, missed an option:
3. You can do Server.MapPath("virtualDir ectoryName ") which will give you path to the virtual directory root. So you would do following in your code:
Replace
Server.MapPath("\")
with
Server.MapPath("virtualDir ectoryName ")
Try that first.
3. You can do Server.MapPath("virtualDir
Replace
Server.MapPath("\")
with
Server.MapPath("virtualDir
Try that first.
ASKER
Actually all of my code is in the D drive along with the images. I just pointed the virtual IIS site to the D drive because my C drive space is sparse. The only thing on C is the "Default Web Site". Also, when you say Server.MapPath("virtualDir ectoryName ") would that be the actual path, or is it a location used by the script?
I'm giving you the points because I think you have gotten me on the right track. Thanks for your patience. If you have anything further to add, I would appreciate it.
One more question actually, why would it be able to upload the file correctly, but then not find it to delete it?
Thanks again,
~S
I'm giving you the points because I think you have gotten me on the right track. Thanks for your patience. If you have anything further to add, I would appreciate it.
One more question actually, why would it be able to upload the file correctly, but then not find it to delete it?
Thanks again,
~S
You are using different objects to upload and delete file. I am not familiar with PureAsp but FSO object requires phisical path to find and delete the file.
Server.MapPath("insert your own virtual directory name here") ===> will result in the physical path to the virtual directory you created on D drive. Try it in your code and then do response.write to ensure you are getting the correct path on D drive.
Server.MapPath("insert your own virtual directory name here") ===> will result in the physical path to the virtual directory you created on D drive. Try it in your code and then do response.write to ensure you are getting the correct path on D drive.
ASKER
Okay, I solved my problem and here's what I had to do:
Moved my physical directory over to C:\inetpub\wwwroot\%Direct ory%
Changed the actual %Directory% name to Lodging to match the virtual directory name
Also, is it possible to ask direct questions to users over Experts Exchange? I really like the way you answer questions and would rather give people like you the points.
~S
Moved my physical directory over to C:\inetpub\wwwroot\%Direct
Changed the actual %Directory% name to Lodging to match the virtual directory name
Also, is it possible to ask direct questions to users over Experts Exchange? I really like the way you answer questions and would rather give people like you the points.
~S
ASKER
Just saw your last reply, I will give the Server.MapPath("virtualPat h") solution a try just to learn a little bit more about it. Thanks for giving me some more insight into how the FSO object works and the fact that they are separate. This really beats pulling my hair out and you've been very helpful in getting me to understand more.
~S
~S
You are welcome. Thanks for the points.
I'm not sure how would you go about posting questions directly to somebody. I think it would be a nice feature and would allow building of smaller support groups. I guess you could let me know when you need something and then add to EE once it's resolved for points. If I'm not available, you can post it to EE right away.
I'm not sure how would you go about posting questions directly to somebody. I think it would be a nice feature and would allow building of smaller support groups. I guess you could let me know when you need something and then add to EE once it's resolved for points. If I'm not available, you can post it to EE right away.
ASKER
Stupid question, but how would I reach you? I actually have another question I'd like answered about books. i.e., which ones might be helpful to someone like me. I'll give it 100 points if that's okay as I just want a basic opinion.
Wasn't aware of that. Thanks for letting me know.
ASKER
Ditto.