Pure ASP Upload Add On Pack Support Product Page
Not deleting old file on update
Asked 08 Aug 2010 16:47:00
1
has this question
08 Aug 2010 16:47:00 karl hemmings posted:
Hi there...I have just purchased this extension and disappointed to find that when applied to my page containing Pure ASP Upload and Update it is not deleting the old file from the folder on the server.
Perhaps you could look at the code and inform me why this is the case?
Here's all code before the header:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> < %' *** Restrict Access To Page: Grant or deny access to this page MM_authorizedUsers="" MM_authFailedURL="teachers-loginfail.asp" MM_grantAccess=false If Session("MM_Username") <> "" Then If (true Or CStr(Session("MM_UserAuthorization"))="") Or _ (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then MM_grantAccess = true End If End If If Not MM_grantAccess Then MM_qsChar = "?" If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&" MM_referrer = Request.ServerVariables("URL") if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString() MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer) Response.Redirect(MM_authFailedURL) End If %> <!--#include file="Connections/databconn10.asp" --> <!--#include file="ScriptLibrary/incPU3Class.asp" --> <!--#include file="ScriptLibrary/incPU3Utils.asp" --> <!--#include file="ScriptLibrary/incPUAddOn.asp" --> < %'*** Pure ASP File Upload 3.0.3 ' Process form form1 Dim pau, DMX_uploadAction, UploadRequest, UploadQueryString, pau_thePath, pau_nameConflict, pau_saveWidth, pau_saveHeight Set pau = new PureUpload pau.ScriptLibrary = "ScriptLibrary" pau.ConflictHandling = "uniq" pau.StoreType = "file" pau.ProgressTemplate = "win_look.htm" pau.ProgressWidth = 400 pau.ProgressHeight = 200 pau.UploadFolder = "" Dim uploadpic set uploadpic = pau.AddField("pic") uploadpic.UploadFolder = """teachers""" uploadpic.Required = true uploadpic.AllowedExtensions = "GIF,JPG,JPEG,BMP,PNG,TIF" ' "images" uploadpic.MaxFileSize = 1000 uploadpic.MinWidth = 250 pau.ProcessUpload pau.SaveAll %> < %Dim MM_editAction MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")) If (UploadQueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(UploadQueryString) End If ' boolean to abort record edit Dim MM_abortEdit MM_abortEdit = false %> < %' IIf implementation Function MM_IIf(condition, ifTrue, ifFalse) If condition = "" Then MM_IIf = ifFalse Else MM_IIf = ifTrue End If End Function %> < %' *** Delete Old Files Before Update Record 1.8.1 If (CStr(UploadFormRequest("MM_update")) <> "" And CStr(UploadFormRequest("MM_recordId")) <> "") Then Dim DOF_suffix DOF_suffix = "" DeleteFileBeforeUpdate pau_thePath,"pic|","pic|",MM_databconn10_STRING,"teachers","ID",UploadFormRequest("MM_recordId"),DOF_suffix end if %> < %If (CStr(UploadFormRequest("MM_update")) = "form1") Then If (Not MM_abortEdit) Then ' execute the update Dim MM_editCmd Set MM_editCmd = Server.CreateObject ("ADODB.Command") MM_editCmd.ActiveConnection = MM_databconn10_STRING MM_editCmd.CommandText = "UPDATE teachers SET pic = ? WHERE ID = ?" MM_editCmd.Prepared = true MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, MM_IIF(UploadFormRequest("pic"), UploadFormRequest("pic"), UploadFormRequest("upload_org_pic"))) ' adVarWChar MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(UploadFormRequest("MM_recordId"), UploadFormRequest("MM_recordId"), null)) ' adDouble MM_editCmd.Execute MM_editCmd.ActiveConnection.Close ' append the query string to the redirect URL Dim MM_editRedirectUrl MM_editRedirectUrl = "teachers-mypictureconfirm.asp" If (UploadQueryString <> "") Then If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then MM_editRedirectUrl = MM_editRedirectUrl & "?" & UploadQueryString Else MM_editRedirectUrl = MM_editRedirectUrl & "&" & UploadQueryString End If End If Response.Redirect(MM_editRedirectUrl) End If End If %> < %Dim User2RS__varMM_Username User2RS__varMM_Username = "0" If (Session("MM_Username") <> "") Then User2RS__varMM_Username = Session("MM_Username") End If %> < %Dim User2RS Dim User2RS_cmd Dim User2RS_numRows Set User2RS_cmd = Server.CreateObject ("ADODB.Command") User2RS_cmd.ActiveConnection = MM_databconn10_STRING User2RS_cmd.CommandText = "SELECT * FROM teachers WHERE email = ?" User2RS_cmd.Prepared = true User2RS_cmd.Parameters.Append User2RS_cmd.CreateParameter("param1", 200, 1, 50, User2RS__varMM_Username) ' adVarChar Set User2RS = User2RS_cmd.Execute User2RS_numRows = 0 %>
Here's the form:
<form ACTION="<%=MM_editAction%>" METHOD="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="<%=pau.submitCode()%>;return document.MM_returnValue"> <label>Locate Picture:</label> <input name="pic" type="file" id="pic" onChange="<%=uploadpic.validateCode()%>;return document.MM_returnValue" /> <br /> <input type="submit" name="button" id="button" value="Upload your Picture >" /> <input type="hidden" name="MM_update" value="form1" /> <input type="hidden" name="MM_recordId" value="<%= User2RS.Fields.Item("ID").Value %>" /> </form>
Any help would be greatly appreciated thank you.
Replies
Replied 16 Aug 2010 11:42:37
16 Aug 2010 11:42:37 Miroslav Zografski replied:
Hello Karl,
The problem in general is that your main upload folder set in PAU defers from the one set up in regards of the upload field you have chosen in PAU UI.
If you set the PAU for all field or set the same folder for the PAU to upload to the problem will be solved. That is because Delete File Before Update is taking the value of pau.UploadFolder as a reference to the folder where you upload your files and looks inside that location to delete the old file. So your code must look like:
Note that now both pau.UploadFolder and uploadfilename.UploadFolder are pointing to one and same folder.
Regards,
The problem in general is that your main upload folder set in PAU defers from the one set up in regards of the upload field you have chosen in PAU UI.
If you set the PAU for all field or set the same folder for the PAU to upload to the problem will be solved. That is because Delete File Before Update is taking the value of pau.UploadFolder as a reference to the folder where you upload your files and looks inside that location to delete the old file. So your code must look like:
< %'*** Pure ASP File Upload 3.0.3 ' Process form form1 Dim pau, DMX_uploadAction, UploadRequest, UploadQueryString, pau_thePath, pau_nameConflict, pau_saveWidth, pau_saveHeight Set pau = new PureUpload pau.ScriptLibrary = "ScriptLibrary" pau.ConflictHandling = "uniq" pau.StoreType = "file" pau.ProgressTemplate = "win_look.htm" pau.ProgressWidth = 400 pau.ProgressHeight = 200 pau.UploadFolder = """teachers""" Dim uploadpic set uploadpic = pau.AddField("pic") uploadpic.UploadFolder = """teachers""" uploadpic.Required = true uploadpic.AllowedExtensions = "GIF,JPG,JPEG,BMP,PNG,TIF" ' "images" uploadpic.MaxFileSize = 1000 uploadpic.MinWidth = 250 pau.ProcessUpload pau.SaveAll %>
Note that now both pau.UploadFolder and uploadfilename.UploadFolder are pointing to one and same folder.
Regards,
Replied 17 Aug 2010 10:37:55
17 Aug 2010 10:37:55 karl hemmings replied:
Thanks Miroslav,
Your solution worked perfectly! [][]
Could this 'bug' be fixed in the next version release?
Hope this helps any other users that have had the same problems?
All the best!
Your solution worked perfectly! [][]
Could this 'bug' be fixed in the next version release?
Hope this helps any other users that have had the same problems?
All the best!
Replied 20 Aug 2010 11:36:39
20 Aug 2010 11:36:39 Miroslav Zografski replied:
Hello Karl,
Will see to add this to extension fix list.
Regards,
Will see to add this to extension fix list.
Regards,