|
<%@ Language=VBScript %>
<!--#include file="../includes/setup.asp" -->
<!--#include file="../includes/inc_Uploader.asp" -->
<!--#include file="../includes/inc_FileUtilities.asp"-->
<%
'#################################################################################
'## Copyright (C) 2003 Rick Eastes
'##
'## This program is free software; you can redistribute it and/or
'## modify it under the terms of the GNU General Public License
'## as published by the Free Software Foundation; either version 2
'## of the License, or any later version.
'##
'## All copyright notices regarding EzyEdit
'## must remain intact in the scripts and in the outputted HTML
'## The "powered by" text/logo with a link back to
'## http://www.ezyedit.com in the footer of the pages MUST
'## remain visible when the pages are viewed on the internet or intranet.
'##
'## This program is distributed in the hope that it will be useful,
'## but WITHOUT ANY WARRANTY; without even the implied warranty of
'## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'## GNU General Public License for more details.
'##
'## You should have received a copy of the GNU General Public License
'## along with this program; if not, write to the Free Software
'## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
'##
'## Support can be obtained from support forums at:
'## http://www.ezyedit.com/forum
'##
'## Correspondence and Marketing Questions can be sent to:
'## rick@ezyedit.com
'## 191 Dorville Rd Carseldine.
'## Brisbane, Australia. 4034
'##
'#################################################################################
server.ScriptTimeout = 999999999
defaultCategory = setup_DefaultFileDir
fileParentUp = setup_RootFileDir + "/" 'Directory in which files are stored
fileParent = "../" & fileParentUp
thispage = "fileLib.asp"
'fileLibrary V2.0 17-FEB-2002
'This file library is to be used as an include and opened in a pop-up window.
if setup_FileUploadMethod = "SAFileUp" then
dim upRequest
Set upRequest = Server.CreateObject("SoftArtisans.FileUp")
action = upRequest.Form("action")
fileCategory = upRequest.Form("fileCategory")
fileName = upRequest.Form("fileName")
deletename = upRequest.Form("deletename")
init = upRequest.Form("action")
else 'Dont use Software Artasians FileUp
Dim oUpload
Dim oFile
Dim sFileName
Dim oFSO
Dim sPath
Dim sNewData
Dim nLength
Dim bytBinaryData
Const nForReading = 1
Const nForWriting = 2
Const nForAppending = 8
' grab the uploaded file data
Set oUpload = New clsUpload
action = oUpload.ValueOf(0)
fileCategory = oUpload.ValueOf(1)
fileName = oUpload.ValueOf(2)
deletename = oUpload.ValueOf(3)
init = oUpload.ValueOf(0)
end if
if len(fileCategory) = 0 then
fileCategory = defaultCategory
end if
%>
<html>
<head>
<title>File Library 2.0</title>
<link rel="STYLESHEET" type="text/css" href="<%=site%>themes/style.css">
<script language=JavaScript>
<!--
function validateFile(strValue)
{
return strValue.length > 0;
}
function validateForm()
{
msg = ""
if( !validateFile(document.fileLib.fileToAdd.value) )
{
msg += 'Please select a file from your local drive by clicking the Browse button.\n';
document.fileLib.fileToAdd.focus();
}
if(msg != '')
{
alert("Sorry:\n" + msg);
document.validForm = (msg == '')
}
else
{
document.validForm = true;
}
}
function Selectfile()
{
var temp;
temp = '<%=fileParent%>' + document.fileLib.fileCategory.value + '/' + document.fileLib.fileName.value
opener.SelectedFileName = temp;
opener.insertFile();
window.close();
}
function SubmitIfGood(formToSubmit)
{
if (window.confirm("Are you sure you wish to DELETE this file?\n"))
{
formToSubmit.submit();
}
}
//-->
</script>
</head>
<BODY bgcolor=black leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<table width=100% height=100% border=0 ID="Table1">
<tr><td valign=top class=fileLibrary>
<font size=2>
<%
if action = "add" then
if setup_FileUploadMethod = "SAFileUp" then
'
dim result
'<!---------- START OF ADD IMAGE CODE-------------->
'Create Server Object AND Get Form Elements
if not IsObject(uprequest.Form("FileToAdd")) Then %>
The form contains a tag named "FileToAdd" which is not of TYPE="FILE". Please
check your form definition.
<%
elseif upRequest.Form("FileToAdd").IsEmpty Then %>
<br>The file that you uploaded was empty. Most likely, you did not specify a valid
filename to your browser or you left the filename field blank. Please try again.
<%
elseIf upRequest.Form("FileToAdd").ContentDisposition <> "form-data" Then %>
<br>Your upload did not succeed, most likely because your browser
does not support Upload via this mechanism.
<br>
<%
else
on error resume next
filename = upRequest.form("FileToAdd").UserFilename
filename = GetFileName(filename)
sPath = Server.MapPath(fileParent) & "\" & fileCategory & "\"
'response.write "PATH: " & sPath & filename
DeleteIfExists( sPath & filename)
upRequest.form("FileToAdd").SaveAs sPath & filename
if Err <> 0 Then %>
An error occurred when saving the file on the server.
<%
else %>
<b><%=sFileName%></b>has been saved in the <b><%=fileCategory%></b> Directory.
<%end if
end if
else ' Don't use SA Fileup for file uploads
Set oFile = oUpload("fileToAdd")
' parse the file name
sFileName = oFile.FileName
If Not InStr(sFileName, "\") = 0 Then
sFileName = Mid(sFileName, InStrRev(sFileName, "\") + 1)
End If
' Convert the binary data to Ascii
bytBinaryData = oFile.BinaryData
nLength = LenB(bytBinaryData)
For nIndex = 1 To nLength
sNewData = sNewData & Chr(AscB(MidB(bytBinaryData, nIndex, 1)))
Next
' Save the file to the file system
sPath = Server.MapPath(fileParent) & "\" & fileCategory & "\"
'response.write "PATH: " & sPath
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
oFSO.OpenTextFile(sPath & sFileName, nForWriting, True).Write sNewData
Set oFSO = Nothing
Set oFile = Nothing
Set oUpload = Nothing
%>
<b><%=sFileName%></b>has been saved in the <b><%=fileCategory%></b> Directory.
<%
end if
End If
if action = "delete" then
if isnull(deletename) Then %>
<br>Error: You must select a file before you delete it. Please try again.<br>
<%
else
DeleteIfExists( Server.MapPath(fileParent & fileCategory & "\" & deletename) )
response.write ("<b>'" & deletename & "'</b> was deleted successfully.")
fileName = ""
end if
end if
%>
</font>
</td>
</tr>
<form name=fileLib action="<%=thispage%>" ENCTYPE="multipart/form-data" method=post ID="Form1">
<input type=hidden name=action value="nothing" ID="Hidden1">
<input type=hidden name=fileCategory value="<%=fileCategory%>" ID="Hidden2">
<input type=hidden name=fileName value="<%=fileName%>" ID="Hidden3">
<input type=hidden name="deletename" value="<%=fileName%>" ID="Hidden4">
<tr>
<td class=fileLibrary valign=top>
<%DirectoryList AbsPath(fileParent), fileCategory, "", ""%>
</td>
</tr>
<tr>
<td class=fileLibrary>
<br><b>Local File:</b><br>
<input type="file" name=fileToAdd size=20 class=inputfield ID="File1">
<br>
<input type="submit" name="btnSubmit" value="Upload" onClick="document.fileLib.action.value='add';validateForm();return document.validForm" class=button ID="Submit1">
<input type=button value="Cancel" onClick="self.close()" class=button ID="Button1" NAME="Button1">
</td>
</tr>
<tr>
<td class=fileLibrary height=100%>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
<%
Function DirectoryList(DirPath, Selected, FirstEntry, FirstEntryValue)
'Generates the directory list from a parent directory
response.write "<table border=0 cellpadding=0 cellspacing=0>"
response.write "<tr><td class=fileLibrary colspan=4><b>Server Files</b><br>Click on a file to insert it</td></tr>"
set fldr = DirListing(DirPath)
chk = ""
for each item in fldr
if Selected = item.name then
response.write "<tr><td colspan=4 class=fileLibrary><img src=""" & site & "gfx/spacer.gif"" width=350 height=0 border=0><br><a href=""javascript:document.fileLib.fileName.value='';document.fileLib.fileCategory.value='" & item.name & "';document.fileLib.submit();"" class=linkdark> <img src=" & site & "gfx\icon-collapse.gif border=0><img src=" & site & "gfx\icon-folder-open2.gif border=0> <b>" & item.name & "</b></a></td></tr>"
'response.write "<tr><td colspan=2><select name=""fileName"" size=10 width=300 onChange=""javascript:document.fileLib.submit();"">"
'response.write FileSelectBox (AbsPath(fileParent & fileCategory), fileName, "", "")
'response.write "</select></td></tr>"
FileList AbsPath(fileParent & fileCategory), fileName, "", ""
else
response.write "<tr><td colspan=4 class=fileLibrary><a href=""javascript:document.fileLib.fileName.value='';document.fileLib.fileCategory.value='" & item.name & "';document.fileLib.submit();"" class=linkdark> <img src=" & site & "gfx\icon-expand.gif border=0><img src=" & site & "gfx\icon-folder.gif border=0> " & item.name & "</a></td></tr>"
end if
next
response.write "</table>"
Set fso = nothing
End Function
Function FileList(DirPath, Selected, FirstEntry, FirstEntryValue)
'Generates the content for HTML from a directory
set fil = FileListing(DirPath)
chk = ""
for each item in fil
if Selected = item.name then
chk = " selected "
else
chk = ""
end if
response.write "<tr><td class=fileLibrary width=200> <a href=""javascript:document.fileLib.fileName.value='" & item.name & "';Selectfile();"" class=linkdark>" & item.name & "</a> </td><td class=fileLibrary><img src=""" & site & "gfx/spacer.gif"" width=60 height=1 border=0><br> (" & round(item.size/1024,2) & " Kb)</td><td class=fileLibrary align=left><a href=""" & fileParent & fileCategory & "/" & item.name & """ class=linkdark target=""_blank""><img src=""" & site & "gfx\icon-next-16.gif"" border=0 hspace=4 align=absmiddle width=16 height=16>Preview</a></td><td class=fileLibrary align=left><a href=""javascript:document.fileLib.fileName.value='" & item.name & "';document.fileLib.action.value='delete';document.fileLib.deletename.value='" & item.name & "';SubmitIfGood(document.fileLib)"" class=linkdark><img src=""" & site & "gfx\icon-delete.gif"" border=0 hspace=4 width=18 height=18 align=absmiddle>Delete</a></td></tr>"
next
Set fso = nothing
End Function
%>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
From Brisbane, Australia.
Likes building stuff.