Forums
This topic is locked
Rename Uploaded Files Question
Posted 29 Jan 2004 19:09:08
1
has voted
29 Jan 2004 19:09:08 Katherine Williams posted:
I've created a page before that uploads & renames with no problem. I did this by using a Session var from a previous page as the filename value. This is what I came up with:<pre id=code><font face=courier size=2 id=code><%
// *** Rename Uploaded Files 1.7.0
if (String(Request.QueryString("GP_upload") != "undefined" {
var REUF_path = ""
var REUF_nameConflict = "over"
var REUF_renameMask = DoTrim( Session("MM_recordId" ,2) + ".##ext##"
RenameUploadedFiles(REUF_path,REUF_nameConflict,REUF_renameMask)
}
%></font id=code></pre id=code>
Now I want to do the same thing, except I want to use a form value from the INSERT form that's being submitted on the same page. This is what I came up with:
<pre id=code><font face=courier size=2 id=code><%
var date = String(UploadFormRequest("txtDate");//Date value stored with slashes, like 01/01/2001
Session("NewDate" = date.replace("/","-"//Changes date value's slashes to dashes, like 01-01/2001
%>
<%
// *** Rename Uploaded Files 1.7.0
if (String(Request.QueryString("GP_upload") != "undefined" {
var REUF_path = ""
var REUF_nameConflict = "over"
var REUF_renameMask = DoTrim( Session("NewDate" ,10) + ".##ext##"
RenameUploadedFiles(REUF_path,REUF_nameConflict,REUF_renameMask);
}
%></font id=code></pre id=code>
But this solution has had some problems:
1) It only replaces the first dash on the date value.
2) It only renames the value in the DB table, not the actual file. This appears to be because it inserts the file into the DB table before it does the Rename SB.
Does anyone see what I need to add and/or change to get this working properly? I've included the code for the entire page at the bottom of this post, so that it all makes more sense. Thanks for any help in advance.
KWilliams
<pre id=code><font face=courier size=2 id=code><%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/strConn_Login.asp" -->
<!--#include file="ScriptLibrary/incPureUpload.asp" -->
<script runat=server language="vbscript" src="ScriptLibrary/dotrim.vbs"></script>
<script runat=server language="vbscript" src="/ScriptLibrary/date_validation.vbs"></script>
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
'*** Pure ASP File Upload 2.1.7
Dim GP_uploadAction,UploadQueryString
PureUploadSetup
If (CStr(Request.QueryString("GP_upload") <> "" Then
Dim pau_thePath,pau_Extensions,pau_Form,pau_Redirect,pau_storeType,pau_sizeLimit,pau_nameConflict,pau_requireUpload,pau_minWidth,pau_minHeight,pau_maxWidth,pau_maxHeight,pau_saveWidth,pau_saveHeight,pau_timeout,pau_progressBar,pau_progressWidth,pau_progressHeight
pau_thePath = """Agenda_Packets"""
pau_Extensions = "PDF"
pau_Form = "form1"
pau_Redirect = ""
pau_storeType = "file"
pau_sizeLimit = ""
pau_nameConflict = "over"
pau_requireUpload = "false"
pau_minWidth = ""
pau_minHeight = ""
pau_maxWidth = ""
pau_maxHeight = ""
pau_saveWidth = ""
pau_saveHeight = ""
pau_timeout = "600"
pau_progressBar = ""
pau_progressWidth = ""
pau_progressHeight = ""
Dim RequestBin, UploadRequest
CheckPureUploadVersion 2.17
ProcessUpload pau_thePath,pau_Extensions,pau_Redirect,pau_storeType,pau_sizeLimit,pau_nameConflict,pau_requireUpload,pau_minWidth,pau_minHeight,pau_maxWidth,pau_maxHeight,pau_saveWidth,pau_saveHeight,pau_timeout
end if
</SCRIPT>
<%
Session("Agenda" = String(UploadFormRequest("text");
Session("Date" = String(UploadFormRequest("txtDate");
Session("Day" = String(UploadFormRequest("txtDay");
Session("Time" = String(UploadFormRequest("txtTime");
Session("MM_Insert" = String(UploadFormRequest("MM_Insert");
Session("Update" = String(UploadFormRequest("hfUpdate");
Session("Packet" = String(UploadFormRequest("filePacket");
%>
<%
var date = String(UploadFormRequest("txtDate");
Session("Year" = date.substring(6,11);
%>
<%
var date = String(UploadFormRequest("txtDate");
Session("NewDate" = date.replace("/","-"
%>
<%
// *** Rename Uploaded Files 1.7.0
if (String(Request.QueryString("GP_upload") != "undefined" {
var REUF_path = ""
var REUF_nameConflict = "over"
var REUF_renameMask = DoTrim( Session("NewDate" ,10) + ".##ext##"
RenameUploadedFiles(REUF_path,REUF_nameConflict,REUF_renameMask);
}
%>
<%
var rsAgendasB__MMColParam = "Agenda_ID";
if(String(Request.QueryString("id") != "undefined" {
rsAgendasB__MMColParam = String(Request.QueryString("id");
}
%>
<%
var rsAgendasB = Server.CreateObject("ADODB.Recordset"
rsAgendasB.ActiveConnection = MM_strConn_Login_STRING;
rsAgendasB.Source = "SELECT * FROM dbo.Commission_Agendas WHERE Agenda_ID = "+ rsAgendasB__MMColParam.replace(/'/g, "''" + " ORDER BY Date DESC";
rsAgendasB.CursorType = 0;
rsAgendasB.CursorLocation = 2;
rsAgendasB.LockType = 3;
rsAgendasB.Open();
var rsAgendasB_numRows = 0;
%>
<%
if(String(Session("Date") != "undefined"{ Command1__varDate = String(Session("Date");}
if(String(Session("Day") != "undefined"{ Command1__varDay = String(Session("Day");}
if(String(Session("Time") != "undefined"{ Command1__varTime = String(Session("Time");}
if(String(Session("Agenda") != "undefined"{ Command1__varAgenda = String(Session("Agenda");}
if(String(Session("Year") != "undefined"{ Command1__varYear = String(Session("Year");}
if(String(Session("Update") != "undefined"{ Command1__varUpdate = String(Session("Update");}
if(String(Session("Packet") != "undefined"{ Command1__varPacket = String(Session("Packet");}
%>
<%
if ((Session("MM_Insert") != "undefined"
{
var Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_strConn_Login_STRING;
Command1.CommandText = "INSERT INTO dbo.Commission_Agendas (Date, Day, Time, Packet, Agenda, Year, Last_Update) VALUES ('"+ Command1__varDate.replace(/'/g, "''" + "', '"+ Command1__varDay.replace(/'/g, "''" + "', '"+ Command1__varTime.replace(/'/g, "''" + "', '"+ Command1__varPacket.replace(/'/g, "''" + "', '"+ Command1__varAgenda.replace(/'/g, "''" + "', '"+ Command1__varYear.replace(/'/g, "''" + "', '"+ Command1__varUpdate.replace(/'/g, "''" + "') ";
Command1.CommandType = 1;
Command1.CommandTimeout = 0;
Command1.Prepared = true;
Command1.Execute();
//Response.Write(Command1.CommandText)Use to test if needed
Command1.Close;
Response.Redirect("/ScriptLibrary/fsoCopyFile.asp"
}
%>
<html>
<head>
<!--#include virtual="/topborder.ssi" -->
<script language="javascript" src="/ScriptLibrary/date_format.js"></script>
<script language="javascript" src="/ScriptLibrary/incPureUpload.js"></script>
</head>
<body>
<!--#include virtual="/topborder2.ssi" -->
<table width="75%" border="0">
<td valign="top" colspan="2">
<table width="100%" border="0" bgcolor="#FFFFCC">
<tr>
<td valign="top">
<form action="<%=GP_uploadAction%>" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="checkFileUpload(this,'PDF',false,'','','','','','','');return document.MM_returnValue">
<table width="100%" border="0">
<tr>
<td width="33%" bgcolor="#330066"><font color="#FFFFFF"><b>Agenda Date:</b></font></td>
<td width="33%" bgcolor="#330066"><font color="#FFFFFF"><b>Agenda Day:</b></font></td>
<td width="33%" bgcolor="#330066"><font color="#FFFFFF"><b>Agenda Time:</b></font></td>
</tr>
<tr>
<td bgcolor="#FFFFCC"><input type="text" name="txtDate" onFocus="javascript:vDateType='1'" onKeyUp="DateFormat(this,this.value,event,false,'1')" onBlur="DateFormat(this,this.value,event,true,'1')" size="20" maxlength="10">
<font size="1" color="#FF0000">(i.e.: mm/dd/yyyy)</font>
</td>
<td bgcolor="#FFFFCC"><input name="txtDay" type="text">
<font size="1" color="#FF0000">(i.e.: Monday)</font> </td>
<td bgcolor="#FFFFCC"><input name="txtTime" type="text">
<font size="1" color="#FF0000">(i.e.: 9:00am)</font> </td>
</tr>
<tr>
<td bgcolor="#330066" valign="top" colspan="3"><font color="#FFFFFF"><b>Agenda Packet (optional) </b></font></td>
</tr>
<tr bgcolor="#FFFFCC">
<td valign="top" colspan="3"><input name="filePacket" type="file" onChange="checkOneFileUpload(this,'PDF',false,'','','','','','','')">
<font size="1" color="#FF0000">(PDF format only)</font></td>
</tr>
<tr>
<td bgcolor="#330066" valign="top" colspan="3">
<p><font color="#FFFFFF"><b>Agenda (copy &
paste)</b></font></p>
</td>
</tr>
</table>
<textarea name="text" style="display:none" rows="1" cols="20"></textarea>
<textarea name="xhtml" style="display:none" rows="1" cols="20"></textarea>
<input type="hidden" name="MM_Insert" value="true">
<input type="hidden" name="hfUpdate" value="<%= kc_Date()%>">
</form>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<div align="right"><object id="richedit" style="BACKGROUND-COLOR: buttonface" data="RTE_Files/richedit.html"width="100%" height="400" type="text/x-scriptlet">
</object>
<script language="JavaScript" event="onload" for="window">
richedit.options="history=yes;source=yes;dragdrop=yes;styleBar=no;style=no;font=no;fontSize=no;colour=no;";
richedit.docHtml = form1.text.innerText;
</script>
<script language="JavaScript" event="onscriptletevent(name, eventData)" for="richedit">
if (name == "post" {
form1.text.value = eventData;
form1.xhtml.value = richedit.docXHtml;
form1.submit();
}
</script>
</div>
</td>
</tr>
<tr>
<td valign="top" colspan="2">
<p> </p>
<div align="center">
<script language="JavaScript" src="dgintrasrv1/footer.js">
</script>
</div>
</td>
</tr>
</table>
</body>
</html>
<%
rsAgendasB.Close();
%></font id=code></pre id=code>
Replies
Replied 29 Jan 2004 22:22:02
29 Jan 2004 22:22:02 Katherine Williams replied:
I've found a solution to one of my two questions: "1) It only replaces the first dash on the date value". Instead of using the JS replace method, I used the SQL SELECT Convert method like this:
<pre id=code><font face=courier size=2 id=code>SELECT Agenda_ID, Day, Time, Year, Agenda, Packet, Last_Update, Date = convert(char(10), Date, 110) FROM dbo.Commission_Agendas</font id=code></pre id=code>
...and it worked great. The converted date gets inserted into the DB table just fine.
But the other problem still exists: "2) It only renames the value in the DB table, not the actual file. This appears to be because it inserts the file into the DB table before it does the Rename SB".
I'm not sure if I have the code in the right order (see new code below), so if anyone sees what I may be doing wrong, it would be great. Thanks.
KWilliams
<pre id=code><font face=courier size=2 id=code>SELECT Agenda_ID, Day, Time, Year, Agenda, Packet, Last_Update, Date = convert(char(10), Date, 110) FROM dbo.Commission_Agendas</font id=code></pre id=code>
...and it worked great. The converted date gets inserted into the DB table just fine.
But the other problem still exists: "2) It only renames the value in the DB table, not the actual file. This appears to be because it inserts the file into the DB table before it does the Rename SB".
I'm not sure if I have the code in the right order (see new code below), so if anyone sees what I may be doing wrong, it would be great. Thanks.
KWilliams
Replied 02 Feb 2004 15:05:01
02 Feb 2004 15:05:01 Patrick Woldberg replied:
You have left the path empty in the rename, this only will work if you store the full path in the database, otherwhise it can't find the file. If you only store the filename then fill in the upload path in the rename behavior also.
--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------
--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------